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