Search in sources :

Example 1 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project camel by apache.

the class IgniteSetTest method testOperations2.

@Test
@SuppressWarnings("unchecked")
public void testOperations2() {
    for (int i = 0; i < 100; i++) {
        template.requestBody("ignite:set:abc?operation=ADD", "hello" + i);
    }
    // SIZE
    int size = template.requestBody("ignite:set:abc?operation=SIZE", "hello", int.class);
    assert_().that(size).isEqualTo(100);
    assert_().that(ignite().set("abc", new CollectionConfiguration()).size()).isEqualTo(100);
    List<String> toRetain = Lists.newArrayList();
    for (int i = 0; i < 50; i++) {
        toRetain.add("hello" + i);
    }
    // RETAIN_ALL
    boolean retained = template.requestBodyAndHeader("ignite:set:abc?operation=CLEAR", toRetain, IgniteConstants.IGNITE_SETS_OPERATION, IgniteSetOperation.RETAIN_ALL, boolean.class);
    assert_().that(retained).isTrue();
    // SIZE
    size = template.requestBody("ignite:set:abc?operation=SIZE", "hello", int.class);
    assert_().that(size).isEqualTo(50);
    assert_().that(ignite().set("abc", new CollectionConfiguration()).size()).isEqualTo(50);
    // ITERATOR
    Iterator<String> iterator = template.requestBody("ignite:set:abc?operation=ITERATOR", "hello", Iterator.class);
    assert_().that(Iterators.toArray(iterator, String.class)).asList().containsExactlyElementsIn(toRetain);
    // ARRAY
    String[] array = template.requestBody("ignite:set:abc?operation=ARRAY", "hello", String[].class);
    assert_().that(array).asList().containsExactlyElementsIn(toRetain);
    // CLEAR
    Object result = template.requestBody("ignite:set:abc?operation=CLEAR", "hello", String.class);
    assert_().that(result).isEqualTo("hello");
    assert_().that(ignite().set("abc", new CollectionConfiguration()).size()).isEqualTo(0);
    // SIZE
    size = template.requestBody("ignite:set:abc?operation=SIZE", "hello", int.class);
    assert_().that(size).isEqualTo(0);
    assert_().that(ignite().set("abc", new CollectionConfiguration()).size()).isEqualTo(0);
}
Also used : IgniteSetEndpoint(org.apache.camel.component.ignite.set.IgniteSetEndpoint) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) Test(org.junit.Test)

Example 2 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project camel by apache.

the class IgniteSetTest method testCollectionsAsCacheObject.

@Test
public void testCollectionsAsCacheObject() {
    // Fill data.
    for (int i = 0; i < 100; i++) {
        template.requestBody("ignite:set:abc?operation=ADD", "hello" + i);
    }
    // Add the set.
    Set<String> toAdd = Sets.newHashSet("hello101", "hello102", "hello103");
    template.requestBody("ignite:set:abc?operation=ADD&treatCollectionsAsCacheObjects=true", toAdd);
    // Size must be 101, not 103.
    int size = template.requestBody("ignite:set:abc?operation=SIZE", "hello", int.class);
    assert_().that(size).isEqualTo(101);
    assert_().that(ignite().set("abc", new CollectionConfiguration()).size()).isEqualTo(101);
    assert_().that(ignite().set("abc", new CollectionConfiguration()).contains(toAdd)).isTrue();
    // Check whether the Set contains the Set.
    boolean contains = template.requestBody("ignite:set:abc?operation=CONTAINS&treatCollectionsAsCacheObjects=true", toAdd, boolean.class);
    assert_().that(contains).isTrue();
    // Delete the Set.
    template.requestBody("ignite:set:abc?operation=REMOVE&treatCollectionsAsCacheObjects=true", toAdd);
    // Size must be 100 again.
    size = template.requestBody("ignite:set:abc?operation=SIZE", "hello", int.class);
    assert_().that(size).isEqualTo(100);
    assert_().that(ignite().set("abc", new CollectionConfiguration()).size()).isEqualTo(100);
    assert_().that(ignite().set("abc", new CollectionConfiguration()).contains(toAdd)).isFalse();
}
Also used : IgniteSetEndpoint(org.apache.camel.component.ignite.set.IgniteSetEndpoint) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) Test(org.junit.Test)

Example 3 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project camel by apache.

the class IgniteSetTest method testWithConfiguration.

@Test
public void testWithConfiguration() {
    CollectionConfiguration configuration = new CollectionConfiguration();
    configuration.setCacheMode(CacheMode.LOCAL);
    context.getRegistry(JndiRegistry.class).bind("config", configuration);
    IgniteSetEndpoint igniteEndpoint = context.getEndpoint("ignite:set:abc?operation=ADD&configuration=#config", IgniteSetEndpoint.class);
    template.requestBody(igniteEndpoint, "hello");
    assert_().that(ignite().set("abc", configuration).size()).isEqualTo(1);
    assert_().that(igniteEndpoint.getConfiguration()).isEqualTo(configuration);
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) IgniteSetEndpoint(org.apache.camel.component.ignite.set.IgniteSetEndpoint) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) Test(org.junit.Test)

Example 4 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project camel by apache.

the class IgniteQueueTest method testCollectionsAsCacheObject.

@Test
public void testCollectionsAsCacheObject() {
    // Fill data.
    for (int i = 0; i < 100; i++) {
        template.requestBody("ignite:queue:abc?operation=ADD", "hello" + i);
    }
    // Add the set.
    Set<String> toAdd = Sets.newHashSet("hello101", "hello102", "hello103");
    template.requestBody("ignite:queue:abc?operation=ADD&treatCollectionsAsCacheObjects=true", toAdd);
    // Size must be 101, not 103.
    int size = template.requestBody("ignite:queue:abc?operation=SIZE", "hello", int.class);
    assert_().that(size).isEqualTo(101);
    assert_().that(ignite().queue("abc", 0, new CollectionConfiguration()).size()).isEqualTo(101);
    assert_().that(ignite().queue("abc", 0, new CollectionConfiguration()).contains(toAdd)).isTrue();
    // Check whether the Set contains the Set.
    boolean contains = template.requestBody("ignite:queue:abc?operation=CONTAINS&treatCollectionsAsCacheObjects=true", toAdd, boolean.class);
    assert_().that(contains).isTrue();
    // Delete the Set.
    template.requestBody("ignite:queue:abc?operation=REMOVE&treatCollectionsAsCacheObjects=true", toAdd);
    // Size must be 100 again.
    size = template.requestBody("ignite:queue:abc?operation=SIZE", "hello", int.class);
    assert_().that(size).isEqualTo(100);
    assert_().that(ignite().queue("abc", 0, new CollectionConfiguration()).size()).isEqualTo(100);
    assert_().that(ignite().queue("abc", 0, new CollectionConfiguration()).contains(toAdd)).isFalse();
}
Also used : IgniteQueueEndpoint(org.apache.camel.component.ignite.queue.IgniteQueueEndpoint) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) Test(org.junit.Test)

Example 5 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.

the class IgniteQueueExample method initializeQueue.

/**
     * Initialize queue.
     *
     * @param ignite Ignite.
     * @param queueName Name of queue.
     * @return Queue.
     * @throws IgniteException If execution failed.
     */
private static IgniteQueue<String> initializeQueue(Ignite ignite, String queueName) throws IgniteException {
    CollectionConfiguration colCfg = new CollectionConfiguration();
    colCfg.setCacheMode(PARTITIONED);
    // Initialize new FIFO queue.
    IgniteQueue<String> queue = ignite.queue(queueName, 0, colCfg);
    // We will be use blocking operation and queue size must be appropriated.
    for (int i = 0; i < ignite.cluster().nodes().size() * RETRIES * 2; i++) queue.put(Integer.toString(i));
    System.out.println("Queue size after initializing: " + queue.size());
    return queue;
}
Also used : CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Aggregations

CollectionConfiguration (org.apache.ignite.configuration.CollectionConfiguration)48 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 ArrayList (java.util.ArrayList)8 IgniteException (org.apache.ignite.IgniteException)8 IgniteQueue (org.apache.ignite.IgniteQueue)7 IgniteCallable (org.apache.ignite.lang.IgniteCallable)7 Test (org.junit.Test)6 Callable (java.util.concurrent.Callable)5 Ignite (org.apache.ignite.Ignite)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IgniteQueueEndpoint (org.apache.camel.component.ignite.queue.IgniteQueueEndpoint)3 IgniteSetEndpoint (org.apache.camel.component.ignite.set.IgniteSetEndpoint)3 IgniteSet (org.apache.ignite.IgniteSet)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 HashSet (java.util.HashSet)2 JndiRegistry (org.apache.camel.impl.JndiRegistry)2 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)2