use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.
the class RingbufferContainerTest method size_whenEmpty.
// ======================= size =======================
@Test
public void size_whenEmpty() {
RingbufferConfig config = new RingbufferConfig("foo").setCapacity(100);
RingbufferContainer ringbuffer = getRingbufferContainer(config);
assertEquals(0, ringbuffer.size());
assertTrue(ringbuffer.isEmpty());
}
use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.
the class RingbufferContainerTest method size_whenAddingManyItems.
@Test
public void size_whenAddingManyItems() {
RingbufferConfig config = new RingbufferConfig("foo").setCapacity(100);
RingbufferContainer<Data, Data> ringbuffer = getRingbufferContainer(config);
for (int k = 0; k < config.getCapacity(); k++) {
ringbuffer.add(toData(""));
assertEquals(k + 1, ringbuffer.size());
}
assertFalse(ringbuffer.isEmpty());
// and therefor the size remains the same
for (int k = 0; k < config.getCapacity(); k++) {
ringbuffer.add(toData(""));
assertEquals(config.getCapacity(), ringbuffer.size());
}
}
use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.
the class RingbufferContainerTest method add_whenWrapped.
@Test
public void add_whenWrapped() {
RingbufferConfig config = new RingbufferConfig("foo").setInMemoryFormat(InMemoryFormat.OBJECT).setCapacity(3);
RingbufferContainer<Data, String> ringbuffer = getRingbufferContainer(config);
ringbuffer.add(toData("1"));
assertEquals(0, ringbuffer.headSequence());
assertEquals(0, ringbuffer.tailSequence());
assertEquals(toData("1"), ringbuffer.readAsData(0));
ringbuffer.add(toData("2"));
assertEquals(1, ringbuffer.tailSequence());
assertEquals(0, ringbuffer.headSequence());
assertEquals(toData("1"), ringbuffer.readAsData(0));
assertEquals(toData("2"), ringbuffer.readAsData(1));
ringbuffer.add(toData("3"));
assertEquals(2, ringbuffer.tailSequence());
assertEquals(0, ringbuffer.headSequence());
assertEquals(toData("1"), ringbuffer.readAsData(0));
assertEquals(toData("2"), ringbuffer.readAsData(1));
assertEquals(toData("3"), ringbuffer.readAsData(2));
ringbuffer.add(toData("4"));
assertEquals(3, ringbuffer.tailSequence());
assertEquals(1, ringbuffer.headSequence());
assertEquals(toData("2"), ringbuffer.readAsData(1));
assertEquals(toData("3"), ringbuffer.readAsData(2));
assertEquals(toData("4"), ringbuffer.readAsData(3));
ringbuffer.add(toData("5"));
assertEquals(4, ringbuffer.tailSequence());
assertEquals(2, ringbuffer.headSequence());
assertEquals(toData("3"), ringbuffer.readAsData(2));
assertEquals(toData("4"), ringbuffer.readAsData(3));
assertEquals(toData("5"), ringbuffer.readAsData(4));
}
use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.
the class RingbufferContainerTest method remainingCapacity_whenTTLDisabled.
@Test
public void remainingCapacity_whenTTLDisabled() {
RingbufferConfig config = new RingbufferConfig("foo").setCapacity(100).setTimeToLiveSeconds(0);
RingbufferContainer<Data, Data> ringbuffer = getRingbufferContainer(config);
assertEquals(config.getCapacity(), ringbuffer.remainingCapacity());
ringbuffer.add(toData("1"));
ringbuffer.add(toData("2"));
assertEquals(config.getCapacity(), ringbuffer.remainingCapacity());
}
use of com.hazelcast.config.RingbufferConfig in project hazelcast by hazelcast.
the class RingbufferAbstractTest method addAsync_whenOverwrite.
private void addAsync_whenOverwrite() throws InterruptedException, ExecutionException {
RingbufferConfig c = config.getRingbufferConfig(ringbuffer.getName());
// fill the buffer with data
for (int k = 0; k < ringbuffer.capacity(); k++) {
ringbuffer.add("old");
}
for (int iteration = 0; iteration < c.getCapacity() * 100; iteration++) {
long oldTail = ringbuffer.tailSequence();
String item = "" + iteration;
long sequence = ringbuffer.addAsync(item, OVERWRITE).toCompletableFuture().get();
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));
}
}
Aggregations