Github user dragonsinth commented on a diff in the pull request:

    https://github.com/apache/lucene-solr/pull/41#discussion_r66172870
  
    --- Diff: 
solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java ---
    @@ -137,6 +136,49 @@ public void testDistributedQueueBlocking() throws 
Exception {
         assertNull(dq.poll());
       }
     
    +  @Test
    +  public void testPeekElements() throws Exception {
    +    String dqZNode = "/distqueue/test";
    +    byte[] data = "hello world".getBytes(UTF8);
    +
    +    DistributedQueue dq = makeDistributedQueue(dqZNode);
    +
    +    // Populate with data.
    +    dq.offer(data);
    +    dq.offer(data);
    +    dq.offer(data);
    +
    +    // Should be able to get 0, 1, 2, or 3 instantly
    +    for (int i = 0; i <= 3; ++i) {
    +      assertEquals(i, dq.peekElements(i, 0, child -> true).size());
    +    }
    +
    +    // Asking for more should return only 3.
    +    assertEquals(3, dq.peekElements(4, 0, child -> true).size());
    +
    +    // If we filter everything out, we should block for the full time.
    +    long start = System.nanoTime();
    +    assertEquals(0, dq.peekElements(4, 1000, child -> false).size());
    +    assertTrue(System.nanoTime() - start >= 
TimeUnit.MILLISECONDS.toNanos(500));
    +
    +    // If someone adds a new matching element while we're waiting, we 
should return immediately.
    +    executor.submit(() -> {
    +      try {
    +        Thread.sleep(500);
    +        dq.offer(data);
    +      } catch (Exception e) {
    +        // ignore
    +      }
    +    });
    +    start = System.nanoTime();
    +    assertEquals(1, dq.peekElements(4, 2000, child -> {
    +      // The 4th element in the queue will end with a "3".
    +      return child.endsWith("3");
    +    }).size());
    +    assertTrue(System.nanoTime() - start < 
TimeUnit.MILLISECONDS.toNanos(1000));
    +    assertTrue(System.nanoTime() - start >= 
TimeUnit.MILLISECONDS.toNanos(250));
    +  }
    +
    --- End diff --
    
    @markrmiller the new test you suggested


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to