use of com.hazelcast.collection.IList in project hazelcast by hazelcast.
the class ClientTxnListTest method testAddRemove.
@Test
public void testAddRemove() throws Exception {
String listName = randomString();
final IList l = client.getList(listName);
l.add("item1");
final TransactionContext context = client.newTransactionContext();
context.beginTransaction();
final TransactionalList<Object> list = context.getList(listName);
assertTrue(list.add("item2"));
assertEquals(2, list.size());
assertEquals(1, l.size());
assertFalse(list.remove("item3"));
assertTrue(list.remove("item1"));
context.commitTransaction();
assertEquals(1, l.size());
}
use of com.hazelcast.collection.IList in project hazelcast by hazelcast.
the class ListListenerTest method testListenerRemove.
@Test
public void testListenerRemove() throws Exception {
final String name = randomString();
final int count = 10;
final int insCount = 4;
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(insCount);
final HazelcastInstance[] instances = factory.newInstances();
ListenerTest listener = new ListenerTest(count);
IList list = getList(instances, name);
list.addItemListener(listener, true);
for (int i = 0; i < count; i++) {
list.add("item" + i);
}
for (int i = count - 1; i >= 0; i--) {
list.remove(i);
}
assertTrue(listener.latchAdd.await(5, TimeUnit.SECONDS));
assertTrue(listener.latchRemove.await(5, TimeUnit.SECONDS));
}
use of com.hazelcast.collection.IList in project hazelcast by hazelcast.
the class TransactionListTest method testSingleListAtomicity.
@Test
public void testSingleListAtomicity() throws ExecutionException, InterruptedException {
final int itemCount = 200;
final HazelcastInstance instance = createHazelcastInstance();
final String name = randomString();
Future<Integer> f = spawn(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
IList<Object> set = instance.getList(name);
while (!set.remove("item-1")) {
}
return set.size();
}
});
TransactionContext context = instance.newTransactionContext();
context.beginTransaction();
TransactionalList<Object> set = context.getList(name);
for (int i = 0; i < itemCount; i++) {
set.add("item-" + i);
}
context.commitTransaction();
int size = f.get();
assertEquals(itemCount - 1, size);
}
use of com.hazelcast.collection.IList in project hazelcast by hazelcast.
the class StreamKafkaPTest method when_projectionFunctionProvided_thenAppliedToReadRecords.
@Test
public void when_projectionFunctionProvided_thenAppliedToReadRecords() {
int messageCount = 20;
Pipeline p = Pipeline.create();
p.readFrom(KafkaSources.<Integer, String, String>kafka(properties(), rec -> rec.value() + "-x", topic1Name)).withoutTimestamps().writeTo(Sinks.list("sink"));
instance().getJet().newJob(p);
sleepAtLeastSeconds(3);
for (int i = 0; i < messageCount; i++) {
kafkaTestSupport.produce(topic1Name, i, Integer.toString(i));
}
IList<String> list = instance().getList("sink");
assertTrueEventually(() -> {
assertEquals(messageCount, list.size());
for (int i = 0; i < messageCount; i++) {
String value = i + "-x";
assertTrue("missing entry: " + value, list.contains(value));
}
}, 5);
}
use of com.hazelcast.collection.IList in project hazelcast by hazelcast.
the class ClientConsoleApp method handleListAddMany.
protected void handleListAddMany(String[] args) {
IList list = getList();
int count = 1;
if (args.length > 1) {
count = Integer.parseInt(args[1]);
}
int successCount = 0;
long t0 = Clock.currentTimeMillis();
for (int i = 0; i < count; i++) {
boolean success = list.add("obj" + i);
if (success) {
successCount++;
}
}
long t1 = Clock.currentTimeMillis();
println("Added " + successCount + " objects.");
println("size = " + list.size() + ", " + successCount * ONE_THOUSAND / (t1 - t0) + " evt/s");
}
Aggregations