shubhamsrkdev commented on code in PR #14964:
URL: https://github.com/apache/lucene/pull/14964#discussion_r2307039991


##########
lucene/sandbox/src/test/org/apache/lucene/sandbox/index/TestBandwidthCappedMergeScheduler.java:
##########
@@ -0,0 +1,382 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.sandbox.index;
+
+import com.carrotsearch.randomizedtesting.generators.RandomStrings;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.ConcurrentMergeScheduler;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.LogDocMergePolicy;
+import org.apache.lucene.index.MergePolicy;
+import org.apache.lucene.index.MergeScheduler;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.lucene.util.InfoStream;
+
+/** Tests for {@link BandwidthCappedMergeScheduler}. */
+public class TestBandwidthCappedMergeScheduler extends LuceneTestCase {
+
+  public void testBasicFunctionality() throws Exception {
+    Directory dir = newDirectory();
+    BandwidthCappedMergeScheduler scheduler = new 
BandwidthCappedMergeScheduler(100.0);
+
+    // Test initial value
+    assertEquals(100.0, scheduler.getMaxMbPerSec(), 0.001);
+
+    scheduler.close();
+    dir.close();
+  }
+
+  public void testBandwidthConfiguration() throws Exception {
+    Directory dir = newDirectory();
+    BandwidthCappedMergeScheduler scheduler = new 
BandwidthCappedMergeScheduler(50.0);
+
+    // Test setting valid bandwidth rates
+    scheduler.setMaxMbPerSec(200.0);
+    assertEquals(200.0, scheduler.getMaxMbPerSec(), 0.001);
+
+    scheduler.setMaxMbPerSec(10.0);
+    assertEquals(10.0, scheduler.getMaxMbPerSec(), 0.001);
+
+    scheduler.close();
+    dir.close();
+  }
+
+  public void testInvalidBandwidthConfiguration() throws Exception {
+    // Test invalid constructor parameter
+    expectThrows(
+        IllegalArgumentException.class,
+        () -> {
+          new BandwidthCappedMergeScheduler(0.0);
+        });
+
+    expectThrows(
+        IllegalArgumentException.class,
+        () -> {
+          new BandwidthCappedMergeScheduler(-1.0);
+        });
+
+    expectThrows(
+        IllegalArgumentException.class,
+        () -> {
+          new BandwidthCappedMergeScheduler(Double.NaN);
+        });
+
+    BandwidthCappedMergeScheduler scheduler = new 
BandwidthCappedMergeScheduler(100.0);
+
+    // Test invalid setMaxMbPerSec values
+    expectThrows(
+        IllegalArgumentException.class,
+        () -> {
+          scheduler.setMaxMbPerSec(0.0);
+        });
+
+    expectThrows(
+        IllegalArgumentException.class,
+        () -> {
+          scheduler.setMaxMbPerSec(-1.0);
+        });
+
+    scheduler.close();
+  }
+
+  public void testToString() throws Exception {
+    BandwidthCappedMergeScheduler scheduler = new 
BandwidthCappedMergeScheduler(50.0);
+    String str = scheduler.toString();
+
+    assertTrue(str.contains("BandwidthCappedMergeScheduler"));
+    assertTrue(str.contains("bandwidthMbPerSec"));
+    assertTrue(str.contains("MB/s"));
+    assertTrue(str.contains("50.0"));
+
+    scheduler.close();
+  }
+
+  public void testWithIndexWriter() throws IOException {
+    Directory dir = newDirectory();
+    BandwidthCappedMergeScheduler scheduler = new 
BandwidthCappedMergeScheduler(100.0);
+
+    IndexWriterConfig config = newIndexWriterConfig();
+    config.setMergeScheduler(scheduler);
+    config.setMaxBufferedDocs(2); // Force frequent flushes
+
+    try (IndexWriter writer = new IndexWriter(dir, config)) {
+      // Add some documents to potentially trigger merges
+      for (int i = 0; i < 20; i++) {
+        Document doc = new Document();
+        doc.add(new StringField("id", String.valueOf(i), Field.Store.YES));
+        doc.add(
+            new TextField(
+                "content",
+                "content " + i + " " + 
RandomStrings.randomRealisticUnicodeOfLength(random(), 100),
+                Field.Store.YES));
+        writer.addDocument(doc);
+
+        if (i % 5 == 0) {
+          writer.commit(); // Force segments
+        }
+      }
+
+      writer.forceMerge(1); // This should trigger merges
+    }
+
+    // The scheduler should have been used
+    assertTrue("Scheduler should have been initialized", 
scheduler.getMaxMbPerSec() > 0);
+
+    scheduler.close();
+    dir.close();
+  }
+
+  public void testBandwidthDistributionAmongMerges() throws IOException {

Review Comment:
   This test has a missing assertion, what are we asserting here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to