Search in sources :

Example 21 with RingbufferConfig

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

the class RingbufferAbstractTest method add_overwritingOldData.

/**
 * In this test we are going to overwrite old data a few times (so we are going round
 * the ring a few times). At the end we expect to see the latest items; everything
 * that is overwritten should not be shown anymore.
 */
@Test
public void add_overwritingOldData() throws Exception {
    RingbufferConfig c = config.getRingbufferConfig(ringbuffer.getName());
    long lastSequence = ringbuffer.tailSequence();
    long expectedTailSeq = 0;
    for (long k = 0; k < 2 * c.getCapacity(); k++) {
        long sequence = ringbuffer.add("item-" + k);
        lastSequence = ringbuffer.tailSequence();
        assertEquals(expectedTailSeq, sequence);
        assertEquals(expectedTailSeq, lastSequence);
        assertEquals(expectedTailSeq, ringbuffer.tailSequence());
        expectedTailSeq++;
    }
    assertEquals(lastSequence - c.getCapacity() + 1, ringbuffer.headSequence());
    // verifying the content
    for (long sequence = ringbuffer.headSequence(); sequence <= ringbuffer.tailSequence(); sequence++) {
        assertEquals("bad content at sequence:" + sequence, "item-" + sequence, ringbuffer.readOne(sequence));
    }
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) Test(org.junit.Test)

Example 22 with RingbufferConfig

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

the class RingbufferAbstractTest method addAllAsync_whenCollectionExceedsCapacity.

@Test
public void addAllAsync_whenCollectionExceedsCapacity() throws Exception {
    RingbufferConfig c = config.getRingbufferConfig(ringbuffer.getName());
    long oldTailSeq = ringbuffer.tailSequence();
    List<String> items = randomList(c.getCapacity() + 20);
    long result = ringbuffer.addAllAsync(items, OVERWRITE).toCompletableFuture().get();
    assertEquals(oldTailSeq + items.size(), ringbuffer.tailSequence());
    assertEquals(ringbuffer.tailSequence() - c.getCapacity() + 1, ringbuffer.headSequence());
    assertEquals(ringbuffer.tailSequence(), result);
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) Test(org.junit.Test)

Example 23 with RingbufferConfig

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

the class RingbufferAddReadOneStressTest method whenNoTTL.

@Test
public void whenNoTTL() throws Exception {
    RingbufferConfig ringbufferConfig = new RingbufferConfig("foo").setCapacity(200 * 1000).setTimeToLiveSeconds(0);
    test(ringbufferConfig);
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 24 with RingbufferConfig

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

the class RingbufferAddReadOneStressTest method whenTTLEnabled.

@Test
public void whenTTLEnabled() throws Exception {
    RingbufferConfig ringbufferConfig = new RingbufferConfig("foo").setCapacity(200 * 1000).setTimeToLiveSeconds(2);
    test(ringbufferConfig);
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 25 with RingbufferConfig

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

the class RingbufferAddReadOneStressTest method test.

public void test(RingbufferConfig ringbufferConfig) throws Exception {
    Config config = new Config();
    config.addRingBufferConfig(ringbufferConfig);
    HazelcastInstance[] instances = createHazelcastInstanceFactory(2).newInstances(config);
    ringbuffer = instances[0].getRingbuffer(ringbufferConfig.getName());
    System.out.println("Starting test");
    ConsumeThread consumer1 = new ConsumeThread(1);
    consumer1.start();
    ConsumeThread consumer2 = new ConsumeThread(2);
    consumer2.start();
    sleepSeconds(2);
    ProduceThread producer = new ProduceThread();
    producer.start();
    long startMs = System.currentTimeMillis();
    sleepAndStop(stop, 3 * 60);
    System.out.println("Waiting for completion");
    producer.assertSucceedsEventually();
    consumer1.assertSucceedsEventually();
    consumer2.assertSucceedsEventually();
    System.out.println("producer.produced:" + producer.produced);
    assertEquals(producer.produced, consumer1.seq);
    assertEquals(producer.produced, consumer2.seq);
    long durationMs = System.currentTimeMillis() - startMs;
    double performance = (1000d * producer.produced) / durationMs;
    System.out.println("Performance: " + performance + " messages per second");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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