Search in sources :

Example 16 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class ReadManyOperationTest method whenBelowMinimumAvailable.

@Test
public void whenBelowMinimumAvailable() {
    long startSequence = ringbuffer.tailSequence() + 1;
    ReadManyOperation op = getReadManyOperation(startSequence, 3, 3, null);
    ringbuffer.add("item1");
    ringbuffer.add("item2");
    assertTrue(op.shouldWait());
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(startSequence + 2, op.sequence);
    assertEquals(asList("item1", "item2"), response);
    assertEquals(2, response.getNextSequenceToReadFrom());
    ringbuffer.add("item3");
    assertFalse(op.shouldWait());
    assertEquals(startSequence + 3, op.sequence);
    assertEquals(asList("item1", "item2", "item3"), response);
    assertEquals(3, response.getNextSequenceToReadFrom());
}
Also used : ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class ReadManyOperationTest method whenFilterProvidedAndAllItemsAvailable.

@Test
public void whenFilterProvidedAndAllItemsAvailable() {
    long startSequence = ringbuffer.tailSequence() + 1;
    IFunction<String, Boolean> filter = (IFunction<String, Boolean>) input -> input.startsWith("good");
    ReadManyOperation op = getReadManyOperation(startSequence, 3, 3, filter);
    ringbuffer.add("bad1");
    ringbuffer.add("good1");
    ringbuffer.add("bad2");
    ringbuffer.add("good2");
    ringbuffer.add("bad3");
    ringbuffer.add("good3");
    assertFalse(op.shouldWait());
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(startSequence + 6, op.sequence);
    assertEquals(asList("good1", "good2", "good3"), response);
    assertEquals(6, response.getNextSequenceToReadFrom());
}
Also used : IFunction(com.hazelcast.core.IFunction) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class ReadManyOperationTest method whenBeforeHead.

@Test
public void whenBeforeHead() throws Exception {
    ringbuffer.add("item1");
    ringbuffer.add("item2");
    ringbuffer.add("item3");
    ringbuffer.add("item4");
    ringbuffer.add("item5");
    ringbufferContainer.setHeadSequence(2);
    ReadManyOperation op = getReadManyOperation(0, 1, 2, null);
    // the start sequence is stale, but it will be clamped to current head
    assertFalse(op.shouldWait());
    op.run();
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(2, response.readCount());
    assertEquals(asList("item3", "item4"), response);
    assertEquals(4, response.getNextSequenceToReadFrom());
    assertEquals(2, response.size());
}
Also used : ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class ReadManyOperationTest method whenOneAfterTail.

@Test
public void whenOneAfterTail() {
    ringbuffer.add("tail");
    ReadManyOperation op = getReadManyOperation(ringbuffer.tailSequence() + 1, 1, 1, null);
    // since there is an item, we don't need to wait
    boolean shouldWait = op.shouldWait();
    assertTrue(shouldWait);
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(0, response.readCount());
    assertEquals(0, response.getNextSequenceToReadFrom());
}
Also used : ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with ReadResultSetImpl

use of com.hazelcast.ringbuffer.impl.ReadResultSetImpl in project hazelcast by hazelcast.

the class ReadManyOperationTest method whenOneAfterTailAndBufferEmpty.

@Test
public void whenOneAfterTailAndBufferEmpty() {
    ReadManyOperation op = getReadManyOperation(ringbuffer.tailSequence() + 1, 1, 1, null);
    // since there is an item, we don't need to wait
    boolean shouldWait = op.shouldWait();
    assertTrue(shouldWait);
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(0, response.readCount());
    assertEquals(0, response.getNextSequenceToReadFrom());
    assertEquals(0, response.size());
}
Also used : ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ReadResultSetImpl (com.hazelcast.ringbuffer.impl.ReadResultSetImpl)20 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 QuickTest (com.hazelcast.test.annotation.QuickTest)14 Test (org.junit.Test)14 Data (com.hazelcast.internal.serialization.Data)3 ArrayList (java.util.ArrayList)3 IFunction (com.hazelcast.core.IFunction)2 ClientDelegatingFuture (com.hazelcast.client.impl.ClientDelegatingFuture)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 CacheEventJournalReadCodec (com.hazelcast.client.impl.protocol.codec.CacheEventJournalReadCodec)1 ResponseParameters (com.hazelcast.client.impl.protocol.codec.CacheEventJournalSubscribeCodec.ResponseParameters)1 MapEventJournalReadCodec (com.hazelcast.client.impl.protocol.codec.MapEventJournalReadCodec)1 RingbufferReadManyCodec (com.hazelcast.client.impl.protocol.codec.RingbufferReadManyCodec)1 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)1 ClientInvocationFuture (com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)1 EventJournalInitialSubscriberState (com.hazelcast.internal.journal.EventJournalInitialSubscriberState)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1