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);
}
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());
}
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;
}
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;
}
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);
}
Aggregations