Search in sources :

Example 36 with RingbufferConfig

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

the class RingbufferContainerTest method read_whenStaleSequence.

@Test(expected = StaleSequenceException.class)
public void read_whenStaleSequence() {
    RingbufferConfig config = new RingbufferConfig("foo").setCapacity(3);
    RingbufferContainer<Data, Data> ringbuffer = getRingbufferContainer(config);
    ringbuffer.add(toData("1"));
    ringbuffer.add(toData("2"));
    ringbuffer.add(toData("3"));
    // this one will overwrite the first item
    ringbuffer.add(toData("4"));
    ringbuffer.readAsData(0);
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 37 with RingbufferConfig

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

the class ReliableTopicCreateTest method testRingbufferConfiguration.

@Test
public void testRingbufferConfiguration() {
    Config config = new Config();
    RingbufferConfig rbConfig = new RingbufferConfig("foo").setCapacity(21);
    config.addRingBufferConfig(rbConfig);
    HazelcastInstance hz = createHazelcastInstance(config);
    RingbufferService ringbufferService = getNodeEngineImpl(hz).getService(RingbufferService.SERVICE_NAME);
    ReliableTopicProxy topic = (ReliableTopicProxy) hz.getReliableTopic("foo");
    Ringbuffer ringbuffer = hz.getRingbuffer(RingbufferService.TOPIC_RB_PREFIX + "foo");
    assertSame(ringbuffer, topic.ringbuffer);
    assertEquals(21, ringbuffer.capacity());
    // triggers the creation
    ringbuffer.size();
    final Map<ObjectNamespace, RingbufferContainer> containers = ringbufferService.getContainers().get(ringbufferService.getRingbufferPartitionId(ringbuffer.getName()));
    final ObjectNamespace ns = RingbufferService.getRingbufferNamespace(ringbuffer.getName());
    assertEquals(1, containers.size());
    assertTrue(containers.containsKey(ns));
    RingbufferContainer container = containers.get(ns);
    assertEquals(rbConfig.getCapacity(), container.getConfig().getCapacity());
}
Also used : RingbufferContainer(com.hazelcast.ringbuffer.impl.RingbufferContainer) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Config(com.hazelcast.config.Config) Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) RingbufferConfig(com.hazelcast.config.RingbufferConfig) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 38 with RingbufferConfig

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

the class TopicOverloadTest method setupCluster.

@Before
public void setupCluster() {
    Config config = new Config();
    config.addRingBufferConfig(new RingbufferConfig("when*").setCapacity(100).setTimeToLiveSeconds(Integer.MAX_VALUE));
    config.addReliableTopicConfig(new ReliableTopicConfig("whenError_*").setTopicOverloadPolicy(TopicOverloadPolicy.ERROR));
    config.addReliableTopicConfig(new ReliableTopicConfig("whenDiscardOldest_*").setTopicOverloadPolicy(TopicOverloadPolicy.DISCARD_OLDEST));
    config.addReliableTopicConfig(new ReliableTopicConfig("whenDiscardNewest_*").setTopicOverloadPolicy(TopicOverloadPolicy.DISCARD_NEWEST));
    config.addReliableTopicConfig(new ReliableTopicConfig("whenBlock_*").setTopicOverloadPolicy(TopicOverloadPolicy.BLOCK));
    HazelcastInstance hz = createHazelcastInstance(config);
    serializationService = getSerializationService(hz);
    String topicName = getTestMethodName();
    topic = hz.<String>getReliableTopic(topicName);
    ringbuffer = ((ReliableTopicProxy<String>) topic).ringbuffer;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) Config(com.hazelcast.config.Config) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Before(org.junit.Before)

Example 39 with RingbufferConfig

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

the class TopicOverloadDistributedTest method setupCluster.

@Before
public void setupCluster() {
    Config config = new Config();
    config.addRingBufferConfig(new RingbufferConfig("when*").setCapacity(100).setTimeToLiveSeconds(Integer.MAX_VALUE));
    config.addReliableTopicConfig(new ReliableTopicConfig("whenError_*").setTopicOverloadPolicy(TopicOverloadPolicy.ERROR));
    config.addReliableTopicConfig(new ReliableTopicConfig("whenDiscardOldest_*").setTopicOverloadPolicy(TopicOverloadPolicy.DISCARD_OLDEST));
    config.addReliableTopicConfig(new ReliableTopicConfig("whenDiscardNewest_*").setTopicOverloadPolicy(TopicOverloadPolicy.DISCARD_NEWEST));
    config.addReliableTopicConfig(new ReliableTopicConfig("whenBlock_*").setTopicOverloadPolicy(TopicOverloadPolicy.BLOCK));
    HazelcastInstance[] hazelcastInstances = createHazelcastInstanceFactory(2).newInstances(config);
    HazelcastInstance hz = hazelcastInstances[0];
    warmUpPartitions(hazelcastInstances);
    serializationService = getSerializationService(hz);
    String topicName = getTestMethodName();
    topic = hz.<String>getReliableTopic(topicName);
    ringbuffer = ((ReliableTopicProxy<String>) topic).ringbuffer;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) Config(com.hazelcast.config.Config) ReliableTopicConfig(com.hazelcast.config.ReliableTopicConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Before(org.junit.Before)

Example 40 with RingbufferConfig

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

the class RingbufferTTLTest method whenTTLDisabled_thenNothingRetires.

@Test
public void whenTTLDisabled_thenNothingRetires() {
    setup(new RingbufferConfig("foo").setTimeToLiveSeconds(0).setCapacity(100));
    for (int k = 0; k < ringbuffer.capacity(); k++) {
        ringbuffer.add("item" + k);
    }
    final long head = ringbuffer.headSequence();
    final long tail = ringbuffer.tailSequence();
    final long size = ringbuffer.size();
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(head, ringbuffer.headSequence());
            assertEquals(tail, ringbuffer.tailSequence());
            assertEquals(size, ringbuffer.size());
            for (long seq = head; seq <= tail; seq++) {
                assertEquals("item" + seq, ringbuffer.readOne(seq));
            }
        }
    }, 5);
}
Also used : RingbufferConfig(com.hazelcast.config.RingbufferConfig) AssertTask(com.hazelcast.test.AssertTask) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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