Search in sources :

Example 1 with IList

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());
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) IList(com.hazelcast.collection.IList) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with IList

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));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) IList(com.hazelcast.collection.IList) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with IList

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) ExecutionException(java.util.concurrent.ExecutionException) IList(com.hazelcast.collection.IList) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with IList

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);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Arrays(java.util.Arrays) IntStream.range(java.util.stream.IntStream.range) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Processor(com.hazelcast.jet.core.Processor) EventTimePolicy(com.hazelcast.jet.core.EventTimePolicy) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) Collections.singletonList(java.util.Collections.singletonList) Future(java.util.concurrent.Future) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) JobStatus(com.hazelcast.jet.core.JobStatus) Collectors.toSet(java.util.stream.Collectors.toSet) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) FunctionEx(com.hazelcast.function.FunctionEx) AfterClass(org.junit.AfterClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Collection(java.util.Collection) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) Category(org.junit.experimental.categories.Category) BroadcastKey(com.hazelcast.jet.core.BroadcastKey) List(java.util.List) IDLE_MESSAGE(com.hazelcast.jet.impl.execution.WatermarkCoalescer.IDLE_MESSAGE) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(java.util.Map.Entry) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) BeforeClass(org.junit.BeforeClass) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) HashMap(java.util.HashMap) TestOutbox(com.hazelcast.jet.core.test.TestOutbox) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) HashSet(java.util.HashSet) Watermark(com.hazelcast.jet.core.Watermark) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Util.entry(com.hazelcast.jet.Util.entry) UuidUtil(com.hazelcast.internal.util.UuidUtil) Nonnull(javax.annotation.Nonnull) Job(com.hazelcast.jet.Job) Before(org.junit.Before) IList(com.hazelcast.collection.IList) TestInbox(com.hazelcast.jet.core.test.TestInbox) JobRepository(com.hazelcast.jet.impl.JobRepository) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) KafkaSources(com.hazelcast.jet.kafka.KafkaSources) WatermarkPolicy.limitingLag(com.hazelcast.jet.core.WatermarkPolicy.limitingLag) ToLongFunctionEx(com.hazelcast.function.ToLongFunctionEx) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) Assert.assertEquals(org.junit.Assert.assertEquals) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with IList

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");
}
Also used : IList(com.hazelcast.collection.IList)

Aggregations

IList (com.hazelcast.collection.IList)12 Test (org.junit.Test)11 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 QuickTest (com.hazelcast.test.annotation.QuickTest)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 Job (com.hazelcast.jet.Job)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 JobConfig (com.hazelcast.jet.config.JobConfig)4 EXACTLY_ONCE (com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE)4 JobRepository (com.hazelcast.jet.impl.JobRepository)4 Assert.assertFalse (org.junit.Assert.assertFalse)4 Category (org.junit.experimental.categories.Category)4 Config (com.hazelcast.config.Config)3 UuidUtil (com.hazelcast.internal.util.UuidUtil)3 JobStatus (com.hazelcast.jet.core.JobStatus)3 TransactionContext (com.hazelcast.transaction.TransactionContext)3 Serializable (java.io.Serializable)3 List (java.util.List)3 Map (java.util.Map)3