Search in sources :

Example 81 with RingbufferConfig

use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.

the class RingbufferContainerTest method size_whenEmpty.

// ======================= size =======================
@Test
public void size_whenEmpty() {
    RingbufferConfig config = new RingbufferConfig("foo").setCapacity(100);
    RingbufferContainer ringbuffer = getRingbufferContainer(config);
    assertEquals(0, ringbuffer.size());
    assertTrue(ringbuffer.isEmpty());
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 82 with RingbufferConfig

use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.

the class RingbufferContainerTest method size_whenAddingManyItems.

@Test
public void size_whenAddingManyItems() {
    RingbufferConfig config = new RingbufferConfig("foo").setCapacity(100);
    RingbufferContainer<Data, Data> ringbuffer = getRingbufferContainer(config);
    for (int k = 0; k < config.getCapacity(); k++) {
        ringbuffer.add(toData(""));
        assertEquals(k + 1, ringbuffer.size());
    }
    assertFalse(ringbuffer.isEmpty());
    // and therefor the size remains the same
    for (int k = 0; k < config.getCapacity(); k++) {
        ringbuffer.add(toData(""));
        assertEquals(config.getCapacity(), ringbuffer.size());
    }
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 83 with RingbufferConfig

use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.

the class RingbufferContainerTest method add_whenWrapped.

@Test
public void add_whenWrapped() {
    RingbufferConfig config = new RingbufferConfig("foo").setInMemoryFormat(InMemoryFormat.OBJECT).setCapacity(3);
    RingbufferContainer<Data, String> ringbuffer = getRingbufferContainer(config);
    ringbuffer.add(toData("1"));
    assertEquals(0, ringbuffer.headSequence());
    assertEquals(0, ringbuffer.tailSequence());
    assertEquals(toData("1"), ringbuffer.readAsData(0));
    ringbuffer.add(toData("2"));
    assertEquals(1, ringbuffer.tailSequence());
    assertEquals(0, ringbuffer.headSequence());
    assertEquals(toData("1"), ringbuffer.readAsData(0));
    assertEquals(toData("2"), ringbuffer.readAsData(1));
    ringbuffer.add(toData("3"));
    assertEquals(2, ringbuffer.tailSequence());
    assertEquals(0, ringbuffer.headSequence());
    assertEquals(toData("1"), ringbuffer.readAsData(0));
    assertEquals(toData("2"), ringbuffer.readAsData(1));
    assertEquals(toData("3"), ringbuffer.readAsData(2));
    ringbuffer.add(toData("4"));
    assertEquals(3, ringbuffer.tailSequence());
    assertEquals(1, ringbuffer.headSequence());
    assertEquals(toData("2"), ringbuffer.readAsData(1));
    assertEquals(toData("3"), ringbuffer.readAsData(2));
    assertEquals(toData("4"), ringbuffer.readAsData(3));
    ringbuffer.add(toData("5"));
    assertEquals(4, ringbuffer.tailSequence());
    assertEquals(2, ringbuffer.headSequence());
    assertEquals(toData("3"), ringbuffer.readAsData(2));
    assertEquals(toData("4"), ringbuffer.readAsData(3));
    assertEquals(toData("5"), ringbuffer.readAsData(4));
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 84 with RingbufferConfig

use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.

the class RingbufferContainerTest method remainingCapacity_whenTTLDisabled.

@Test
public void remainingCapacity_whenTTLDisabled() {
    RingbufferConfig config = new RingbufferConfig("foo").setCapacity(100).setTimeToLiveSeconds(0);
    RingbufferContainer<Data, Data> ringbuffer = getRingbufferContainer(config);
    assertEquals(config.getCapacity(), ringbuffer.remainingCapacity());
    ringbuffer.add(toData("1"));
    ringbuffer.add(toData("2"));
    assertEquals(config.getCapacity(), ringbuffer.remainingCapacity());
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 85 with RingbufferConfig

use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.

the class RingbufferAbstractTest method addAsync_whenOverwrite.

private void addAsync_whenOverwrite() throws InterruptedException, ExecutionException {
    RingbufferConfig c = config.getRingbufferConfig(ringbuffer.getName());
    // fill the buffer with data
    for (int k = 0; k < ringbuffer.capacity(); k++) {
        ringbuffer.add("old");
    }
    for (int iteration = 0; iteration < c.getCapacity() * 100; iteration++) {
        long oldTail = ringbuffer.tailSequence();
        String item = "" + iteration;
        long sequence = ringbuffer.addAsync(item, OVERWRITE).toCompletableFuture().get();
        long expectedSequence = oldTail + 1;
        assertEquals(expectedSequence, sequence);
        assertEquals(expectedSequence, ringbuffer.tailSequence());
        if (ringbuffer.tailSequence() < c.getCapacity()) {
            assertEquals(0, ringbuffer.headSequence());
        } else {
            assertEquals(ringbuffer.tailSequence() - c.getCapacity() + 1, ringbuffer.headSequence());
        }
        assertEquals(item, ringbuffer.readOne(expectedSequence));
    }
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig)

Aggregations

RingbufferConfig (com.hazelcast.config.RingbufferConfig)91 Test (org.junit.Test)43 Config (com.hazelcast.config.Config)35 QuickTest (com.hazelcast.test.annotation.QuickTest)26 HazelcastInstance (com.hazelcast.core.HazelcastInstance)22 Before (org.junit.Before)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)14 NightlyTest (com.hazelcast.test.annotation.NightlyTest)12 ReliableTopicConfig (com.hazelcast.config.ReliableTopicConfig)11 RingbufferStoreConfig (com.hazelcast.config.RingbufferStoreConfig)9 Data (com.hazelcast.internal.serialization.Data)7 TopicConfig (com.hazelcast.config.TopicConfig)6 ClientConfig (com.hazelcast.client.config.ClientConfig)5 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)5 CardinalityEstimatorConfig (com.hazelcast.config.CardinalityEstimatorConfig)5 DurableExecutorConfig (com.hazelcast.config.DurableExecutorConfig)5 ExecutorConfig (com.hazelcast.config.ExecutorConfig)5 FlakeIdGeneratorConfig (com.hazelcast.config.FlakeIdGeneratorConfig)5 ListConfig (com.hazelcast.config.ListConfig)5 MapConfig (com.hazelcast.config.MapConfig)5