Search in sources :

Example 16 with RingbufferConfig

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

the class RingbufferStoreTest method getConfig.

private static Config getConfig(String ringbufferName, int capacity, InMemoryFormat inMemoryFormat, RingbufferStoreConfig ringbufferStoreConfig) {
    final Config config = new Config();
    final RingbufferConfig rbConfig = config.getRingbufferConfig(ringbufferName).setInMemoryFormat(inMemoryFormat).setCapacity(capacity);
    rbConfig.setRingbufferStoreConfig(ringbufferStoreConfig);
    return config;
}
Also used : RingbufferStoreConfig(com.hazelcast.config.RingbufferStoreConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) RingbufferConfig(com.hazelcast.config.RingbufferConfig)

Example 17 with RingbufferConfig

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

the class RingbufferAbstractTest method readOne_whenBeforeHead_thenStaleSequenceException.

@Test
public void readOne_whenBeforeHead_thenStaleSequenceException() throws Exception {
    RingbufferConfig ringbufferConfig = config.getRingbufferConfig(ringbuffer.getName());
    for (int k = 0; k < ringbufferConfig.getCapacity() * 2; k++) {
        ringbuffer.add("foo");
    }
    long headSeq = ringbuffer.headSequence();
    try {
        ringbuffer.readOne(headSeq - 1);
        fail();
    } catch (StaleSequenceException expected) {
        assertEquals(headSeq, expected.getHeadSeq());
    }
}
Also used : StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Test(org.junit.Test)

Example 18 with RingbufferConfig

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

the class RingbufferAbstractTest method add_manyTimesRoundTheRing.

// this test verifies that the add works correctly if we go round the ringbuffer many times.
@Test
public void add_manyTimesRoundTheRing() throws Exception {
    RingbufferConfig c = config.getRingbufferConfig(ringbuffer.getName());
    for (int iteration = 0; iteration < c.getCapacity() * 100; iteration++) {
        long oldTail = ringbuffer.tailSequence();
        String item = "" + iteration;
        long sequence = ringbuffer.add(item);
        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) Test(org.junit.Test)

Example 19 with RingbufferConfig

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

the class RingbufferAbstractTest method addAllAsync_manyTimesRoundTheRing.

// this test verifies that the addAllAsync works correctly if we go round the ringbuffer many times.
@Test
public void addAllAsync_manyTimesRoundTheRing() throws Exception {
    RingbufferConfig c = config.getRingbufferConfig(ringbuffer.getName());
    Random random = new Random();
    for (int iteration = 0; iteration < 1000; iteration++) {
        List<String> items = randomList(max(1, random.nextInt(c.getCapacity())));
        long previousTailSeq = ringbuffer.tailSequence();
        long result = ringbuffer.addAllAsync(items, OVERWRITE).toCompletableFuture().get();
        assertEquals(previousTailSeq + items.size(), ringbuffer.tailSequence());
        if (ringbuffer.tailSequence() < c.getCapacity()) {
            assertEquals(0, ringbuffer.headSequence());
        } else {
            assertEquals(ringbuffer.tailSequence() - c.getCapacity() + 1, ringbuffer.headSequence());
        }
        assertEquals(ringbuffer.tailSequence(), result);
        long startSequence = previousTailSeq + 1;
        for (int k = 0; k < items.size(); k++) {
            assertEquals(items.get(k), ringbuffer.readOne(startSequence + k));
        }
    }
}
Also used : Random(java.util.Random) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Test(org.junit.Test)

Example 20 with RingbufferConfig

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

the class RingbufferAbstractTest method initAndGetConfig.

public static Config initAndGetConfig() {
    Config config = smallInstanceConfig();
    config.addRingBufferConfig(new RingbufferConfig("add_overwritingOldData*").setCapacity(5));
    config.addRingBufferConfig(new RingbufferConfig("add_manyTimesRoundTheRing*").setCapacity(5));
    config.addRingBufferConfig(new RingbufferConfig("readOne_whenBeforeHead*").setCapacity(5));
    config.addRingBufferConfig(new RingbufferConfig("readOne_whenObjectInMemoryFormat*").setCapacity(5).setInMemoryFormat(OBJECT));
    config.addRingBufferConfig(new RingbufferConfig("readManyAsync_whenEnoughItems_andObjectInMemoryFormat*").setCapacity(5).setInMemoryFormat(OBJECT));
    config.addRingBufferConfig(new RingbufferConfig("addAsync_whenOverwrite_andNoTTL*").setCapacity(300).setTimeToLiveSeconds(0));
    config.addRingBufferConfig(new RingbufferConfig("addAllAsync_whenCollectionExceedsCapacity*").setCapacity(5));
    config.addRingBufferConfig(new RingbufferConfig("addAllAsync_manyTimesRoundTheRing*").setCapacity(50));
    config.addRingBufferConfig(new RingbufferConfig("addAllAsync_whenObjectInMemoryFormat*").setCapacity(50).setInMemoryFormat(OBJECT));
    config.addRingBufferConfig(new RingbufferConfig("addAsync_fail_whenNoSpace*").setCapacity(300).setTimeToLiveSeconds(10));
    config.addRingBufferConfig(new RingbufferConfig("addAsync_whenOverwrite_andTTL*").setCapacity(300));
    config.addRingBufferConfig(new RingbufferConfig("addAsync_whenOverwrite_andNoTTL*").setCapacity(300).setTimeToLiveSeconds(0));
    config.addRingBufferConfig(new RingbufferConfig("remainingCapacity*").setCapacity(300).setTimeToLiveSeconds(10));
    config.addRingBufferConfig(new RingbufferConfig("readOne_staleSequence*").setCapacity(5));
    config.addRingBufferConfig(new RingbufferConfig("readOne_futureSequence*").setCapacity(5));
    config.addRingBufferConfig(new RingbufferConfig("sizeShouldNotExceedCapacity_whenPromotedFromBackup*").setCapacity(10));
    config.addRingBufferConfig(new RingbufferConfig("readManyAsync_whenHitsStale_shouldNotBeBlocked*").setCapacity(10));
    config.addRingBufferConfig(new RingbufferConfig("readOne_whenHitsStale_shouldNotBeBlocked*").setCapacity(10));
    return config;
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) 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