Search in sources :

Example 11 with ReadResultSetImpl

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

the class ReadManyOperationTest method whenBeforeTail.

@Test
public void whenBeforeTail() throws Exception {
    ringbuffer.add("item1");
    ringbuffer.add("item2");
    ringbuffer.add("item3");
    ReadManyOperation op = getReadManyOperation(ringbuffer.tailSequence() - 1, 1, 1, null);
    // since there is an item, we don't need to wait
    boolean shouldWait = op.shouldWait();
    assertFalse(shouldWait);
    op.run();
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(asList("item2"), response);
    assertEquals(1, response.readCount());
    assertEquals(2, response.getNextSequenceToReadFrom());
    assertEquals(1, 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 12 with ReadResultSetImpl

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

the class ReadManyOperationTest method whenAtHead.

@Test
public void whenAtHead() throws Exception {
    ringbuffer.add("item1");
    ringbuffer.add("item2");
    ringbuffer.add("item3");
    ReadManyOperation op = getReadManyOperation(ringbuffer.headSequence(), 1, 1, null);
    op.setNodeEngine(nodeEngine);
    // since there is an item, we don't need to wait
    boolean shouldWait = op.shouldWait();
    assertFalse(shouldWait);
    op.run();
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(asList("item1"), response);
    assertEquals(1, response.readCount());
    assertEquals(1, response.getNextSequenceToReadFrom());
    assertEquals(1, 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 13 with ReadResultSetImpl

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

the class ClientCacheProxy method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    eventJournalReadResponseDecoder = message -> {
        final CacheEventJournalReadCodec.ResponseParameters params = CacheEventJournalReadCodec.decodeResponse(message);
        final ReadResultSetImpl resultSet = new ReadResultSetImpl<>(params.readCount, params.items, params.itemSeqs, params.nextSeq);
        resultSet.setSerializationService(getSerializationService());
        return resultSet;
    };
    eventJournalSubscribeResponseDecoder = message -> {
        final ResponseParameters resp = CacheEventJournalSubscribeCodec.decodeResponse(message);
        return new EventJournalInitialSubscriberState(resp.oldestSequence, resp.newestSequence);
    };
}
Also used : EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState) CacheEventJournalReadCodec(com.hazelcast.client.impl.protocol.codec.CacheEventJournalReadCodec) ResponseParameters(com.hazelcast.client.impl.protocol.codec.CacheEventJournalSubscribeCodec.ResponseParameters) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl)

Example 14 with ReadResultSetImpl

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

the class RingbufferReadManyMessageTask method encodeResponse.

@Override
protected ClientMessage encodeResponse(Object response) {
    // we are not deserializing the whole content, only the enclosing portable. The actual items remain un
    final ReadResultSetImpl resultSet = nodeEngine.getSerializationService().toObject(response);
    final List<Data> items = new ArrayList<Data>(resultSet.size());
    final long[] seqs = new long[resultSet.size()];
    final Data[] dataItems = resultSet.getDataItems();
    for (int k = 0; k < resultSet.size(); k++) {
        items.add(dataItems[k]);
        seqs[k] = resultSet.getSequence(k);
    }
    return RingbufferReadManyCodec.encodeResponse(resultSet.readCount(), items, seqs, resultSet.getNextSequenceToReadFrom());
}
Also used : ArrayList(java.util.ArrayList) Data(com.hazelcast.internal.serialization.Data) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl)

Example 15 with ReadResultSetImpl

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

the class ClientRingbufferProxy method onInitialize.

@Override
protected void onInitialize() {
    String partitionKey = StringPartitioningStrategy.getPartitionKey(name);
    partitionId = getContext().getPartitionService().getPartitionId(partitionKey);
    readManyAsyncResponseDecoder = clientMessage -> {
        final RingbufferReadManyCodec.ResponseParameters params = RingbufferReadManyCodec.decodeResponse(clientMessage);
        final ReadResultSetImpl readResultSet = new ReadResultSetImpl(params.readCount, params.items, params.itemSeqs, params.nextSeq);
        readResultSet.setSerializationService(getSerializationService());
        return readResultSet;
    };
}
Also used : RingbufferReadManyCodec(com.hazelcast.client.impl.protocol.codec.RingbufferReadManyCodec) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl)

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