Search in sources :

Example 1 with ReadResultSet

use of com.hazelcast.ringbuffer.ReadResultSet in project hazelcast by hazelcast.

the class RingbufferTest method readManyAsync_noFilter.

@Test
public void readManyAsync_noFilter() throws Exception {
    serverRingbuffer.add("1");
    serverRingbuffer.add("2");
    serverRingbuffer.add("3");
    Future<ReadResultSet<String>> f = clientRingbuffer.readManyAsync(0, 3, 3, null).toCompletableFuture();
    ReadResultSet rs = f.get();
    assertInstanceOf(ReadResultSetImpl.class, rs);
    assertEquals(3, rs.readCount());
    assertEquals("1", rs.get(0));
    assertEquals("2", rs.get(1));
    assertEquals("3", rs.get(2));
}
Also used : ReadResultSet(com.hazelcast.ringbuffer.ReadResultSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ReadResultSet

use of com.hazelcast.ringbuffer.ReadResultSet in project hazelcast by hazelcast.

the class RingbufferTest method readManyAsync_withFilter.

@Test
public void readManyAsync_withFilter() throws Exception {
    serverRingbuffer.add("good1");
    serverRingbuffer.add("bad1");
    serverRingbuffer.add("good2");
    serverRingbuffer.add("bad2");
    serverRingbuffer.add("good3");
    serverRingbuffer.add("bad3");
    Future<ReadResultSet<String>> f = clientRingbuffer.readManyAsync(0, 3, 3, new StartsWithStringFilter("good")).toCompletableFuture();
    ReadResultSet rs = f.get();
    assertInstanceOf(ReadResultSetImpl.class, rs);
    assertEquals(5, rs.readCount());
    assertEquals("good1", rs.get(0));
    assertEquals("good2", rs.get(1));
    assertEquals("good3", rs.get(2));
}
Also used : StartsWithStringFilter(com.hazelcast.client.test.ringbuffer.filter.StartsWithStringFilter) ReadResultSet(com.hazelcast.ringbuffer.ReadResultSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with ReadResultSet

use of com.hazelcast.ringbuffer.ReadResultSet in project hazelcast by hazelcast.

the class RingbufferTest method readManyAsync_withFilter_andMaxCount.

// checks if the max count works in combination with a filter.
// So if more results are available than needed, the surplus results should not be read.
@Test
public void readManyAsync_withFilter_andMaxCount() throws Exception {
    serverRingbuffer.add("good1");
    serverRingbuffer.add("bad1");
    serverRingbuffer.add("good2");
    serverRingbuffer.add("bad2");
    serverRingbuffer.add("good3");
    serverRingbuffer.add("bad3");
    serverRingbuffer.add("good4");
    serverRingbuffer.add("bad4");
    Future<ReadResultSet<String>> f = clientRingbuffer.readManyAsync(0, 3, 3, new StartsWithStringFilter("good")).toCompletableFuture();
    ReadResultSet rs = f.get();
    assertInstanceOf(ReadResultSetImpl.class, rs);
    assertEquals(5, rs.readCount());
    assertEquals("good1", rs.get(0));
    assertEquals("good2", rs.get(1));
    assertEquals("good3", rs.get(2));
}
Also used : StartsWithStringFilter(com.hazelcast.client.test.ringbuffer.filter.StartsWithStringFilter) ReadResultSet(com.hazelcast.ringbuffer.ReadResultSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ReadResultSet

use of com.hazelcast.ringbuffer.ReadResultSet in project hazelcast by hazelcast.

the class RingbufferAbstractTest method readManyAsync_whenHitsStale_useHeadAsStartSequence.

@Test
public void readManyAsync_whenHitsStale_useHeadAsStartSequence() throws Exception {
    ringbuffer.addAllAsync(asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), OVERWRITE);
    Future<ReadResultSet<String>> f = ringbuffer.readManyAsync(1, 1, 10, null).toCompletableFuture();
    ReadResultSet rs = f.get();
    assertEquals(10, rs.readCount());
    assertEquals("1", rs.get(0));
    assertEquals("10", rs.get(9));
}
Also used : ReadResultSet(com.hazelcast.ringbuffer.ReadResultSet) Test(org.junit.Test)

Example 5 with ReadResultSet

use of com.hazelcast.ringbuffer.ReadResultSet in project hazelcast by hazelcast.

the class AbstractEventJournalBasicTest method allowReadingWithFutureSeq.

@Test
public void allowReadingWithFutureSeq() throws Exception {
    final EventJournalTestContext<String, Integer, EJ_TYPE> context = createContext();
    final EventJournalInitialSubscriberState state = subscribeToEventJournal(context.dataAdapter, partitionId);
    assertEquals(0, state.getOldestSequence());
    assertEquals(-1, state.getNewestSequence());
    assertEventJournalSize(context.dataAdapter, 0);
    final Integer value = RANDOM.nextInt();
    final CountDownLatch latch = new CountDownLatch(1);
    final int startSequence = 1;
    final BiConsumer<ReadResultSet<EJ_TYPE>, Throwable> callback = (response, t) -> {
        if (t == null) {
            latch.countDown();
            assertEquals(1, response.size());
            final EventJournalEventAdapter<String, Integer, EJ_TYPE> journalAdapter = context.eventJournalAdapter;
            final EJ_TYPE e = response.get(0);
            assertEquals(ADDED, journalAdapter.getType(e));
            assertEquals(value, journalAdapter.getNewValue(e));
        } else {
            rethrow(t);
        }
    };
    CompletionStage<ReadResultSet<EJ_TYPE>> callbackStage = readFromEventJournal(context.dataAdapter, startSequence, 1, partitionId, TRUE_PREDICATE, IDENTITY_FUNCTION).whenCompleteAsync(callback);
    assertTrueEventually(() -> {
        context.dataAdapter.put(randomPartitionKey(), value);
        assertTrue(latch.await(200, TimeUnit.MILLISECONDS));
    }, 30);
    // ensure no exception thrown from callback
    callbackStage.toCompletableFuture().join();
}
Also used : ADDED(com.hazelcast.journal.EventJournalEventAdapter.EventType.ADDED) EventType(com.hazelcast.journal.EventJournalEventAdapter.EventType) EventJournalConfig(com.hazelcast.config.EventJournalConfig) HashMap(java.util.HashMap) Random(java.util.Random) Function(java.util.function.Function) ExceptionUtil.rethrow(com.hazelcast.internal.util.ExceptionUtil.rethrow) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) LOADED(com.hazelcast.journal.EventJournalEventAdapter.EventType.LOADED) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) Accessors.getNode(com.hazelcast.test.Accessors.getNode) BiConsumer(java.util.function.BiConsumer) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) Before(org.junit.Before) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) Predicate(java.util.function.Predicate) Assert.assertNotNull(org.junit.Assert.assertNotNull) SetUtil(com.hazelcast.internal.util.SetUtil) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Node(com.hazelcast.instance.impl.Node) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) CompletionStage(java.util.concurrent.CompletionStage) Assert.assertNull(org.junit.Assert.assertNull) Entry(java.util.Map.Entry) AssertTask(com.hazelcast.test.AssertTask) ReadResultSet(com.hazelcast.ringbuffer.ReadResultSet) EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState) EVICTED(com.hazelcast.journal.EventJournalEventAdapter.EventType.EVICTED) Assert.assertEquals(org.junit.Assert.assertEquals) ReadResultSet(com.hazelcast.ringbuffer.ReadResultSet) CountDownLatch(java.util.concurrent.CountDownLatch) EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState) Test(org.junit.Test)

Aggregations

ReadResultSet (com.hazelcast.ringbuffer.ReadResultSet)11 Test (org.junit.Test)11 QuickTest (com.hazelcast.test.annotation.QuickTest)6 AssertTask (com.hazelcast.test.AssertTask)3 StartsWithStringFilter (com.hazelcast.client.test.ringbuffer.filter.StartsWithStringFilter)2 StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)2 DistributedObjectDestroyedException (com.hazelcast.spi.exception.DistributedObjectDestroyedException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 Config (com.hazelcast.config.Config)1 EventJournalConfig (com.hazelcast.config.EventJournalConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Node (com.hazelcast.instance.impl.Node)1 EventJournalInitialSubscriberState (com.hazelcast.internal.journal.EventJournalInitialSubscriberState)1 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)1 ExceptionUtil.rethrow (com.hazelcast.internal.util.ExceptionUtil.rethrow)1 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)1 SetUtil (com.hazelcast.internal.util.SetUtil)1 EventType (com.hazelcast.journal.EventJournalEventAdapter.EventType)1 ADDED (com.hazelcast.journal.EventJournalEventAdapter.EventType.ADDED)1