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