Search in sources :

Example 1 with IFunction

use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.

the class ClientQueryCacheTest method testQueryCacheCleared_afterCalling_IMap_clear.

@Test
public void testQueryCacheCleared_afterCalling_IMap_clear() {
    String cacheName = randomString();
    final IMap<Integer, Integer> map = getMap();
    QueryCache<Integer, Integer> queryCache = map.getQueryCache(cacheName, TRUE_PREDICATE, false);
    for (int i = 0; i < 1000; i++) {
        map.put(i, i);
    }
    IFunction clear = new IFunction() {

        @Override
        public Object apply(Object ignored) {
            map.clear();
            return null;
        }
    };
    assertQueryCacheSizeEventually(0, clear, queryCache);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IFunction(com.hazelcast.core.IFunction) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with IFunction

use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.

the class AlterOperation method run.

@Override
public void run() throws Exception {
    NodeEngine nodeEngine = getNodeEngine();
    IFunction f = nodeEngine.toObject(function);
    AtomicReferenceContainer reference = getReferenceContainer();
    Data originalData = reference.get();
    Object input = nodeEngine.toObject(originalData);
    //noinspection unchecked
    Object output = f.apply(input);
    Data serializedOutput = nodeEngine.toData(output);
    shouldBackup = !isEquals(originalData, serializedOutput);
    if (shouldBackup) {
        backup = serializedOutput;
        reference.set(backup);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) AtomicReferenceContainer(com.hazelcast.concurrent.atomicreference.AtomicReferenceContainer) Data(com.hazelcast.nio.serialization.Data) IFunction(com.hazelcast.core.IFunction)

Example 3 with IFunction

use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.

the class ApplyOperation method run.

@Override
public void run() throws Exception {
    NodeEngine nodeEngine = getNodeEngine();
    IFunction f = nodeEngine.toObject(function);
    AtomicReferenceContainer atomicReferenceContainer = getReferenceContainer();
    Object input = nodeEngine.toObject(atomicReferenceContainer.get());
    //noinspection unchecked
    Object output = f.apply(input);
    returnValue = nodeEngine.toData(output);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) AtomicReferenceContainer(com.hazelcast.concurrent.atomicreference.AtomicReferenceContainer) IFunction(com.hazelcast.core.IFunction)

Example 4 with IFunction

use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.

the class GetAndAlterOperation method run.

@Override
public void run() throws Exception {
    NodeEngine nodeEngine = getNodeEngine();
    IFunction f = nodeEngine.toObject(function);
    AtomicReferenceContainer atomicReferenceContainer = getReferenceContainer();
    response = atomicReferenceContainer.get();
    Object input = nodeEngine.toObject(atomicReferenceContainer.get());
    //noinspection unchecked
    Object output = f.apply(input);
    Data serializedOutput = nodeEngine.toData(output);
    shouldBackup = !isEquals(response, serializedOutput);
    if (shouldBackup) {
        atomicReferenceContainer.set(serializedOutput);
        backup = serializedOutput;
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) AtomicReferenceContainer(com.hazelcast.concurrent.atomicreference.AtomicReferenceContainer) Data(com.hazelcast.nio.serialization.Data) IFunction(com.hazelcast.core.IFunction)

Example 5 with IFunction

use of com.hazelcast.core.IFunction in project hazelcast by hazelcast.

the class ReadManyOperationTest method whenFilterProvidedAndNoItemsAvailable.

@Test
public void whenFilterProvidedAndNoItemsAvailable() throws Exception {
    long startSequence = ringbuffer.tailSequence() + 1;
    IFunction<String, Boolean> filter = new IFunction<String, Boolean>() {

        @Override
        public Boolean apply(String input) {
            return input.startsWith("good");
        }
    };
    ReadManyOperation op = new ReadManyOperation(ringbuffer.getName(), startSequence, 3, 3, filter);
    op.setNodeEngine(nodeEngine);
    assertTrue(op.shouldWait());
    ReadResultSetImpl response = getReadResultSet(op);
    assertEquals(startSequence, op.sequence);
    assertTrue(getReadResultSet(op).isEmpty());
    ringbuffer.add("bad1");
    assertTrue(op.shouldWait());
    assertEquals(startSequence + 1, op.sequence);
    assertEquals(1, response.readCount());
    assertEquals(0, response.size());
    ringbuffer.add("good1");
    assertTrue(op.shouldWait());
    assertEquals(startSequence + 2, op.sequence);
    assertEquals(asList("good1"), response);
    assertEquals(2, response.readCount());
    ringbuffer.add("bad2");
    assertTrue(op.shouldWait());
    assertEquals(startSequence + 3, op.sequence);
    assertEquals(asList("good1"), response);
    assertEquals(3, response.readCount());
    ringbuffer.add("good2");
    assertTrue(op.shouldWait());
    assertEquals(startSequence + 4, op.sequence);
    assertEquals(asList("good1", "good2"), response);
    assertEquals(4, response.readCount());
    ringbuffer.add("bad3");
    assertTrue(op.shouldWait());
    assertEquals(startSequence + 5, op.sequence);
    assertEquals(asList("good1", "good2"), response);
    assertEquals(5, response.readCount());
    ringbuffer.add("good3");
    assertFalse(op.shouldWait());
    assertEquals(startSequence + 6, op.sequence);
    assertEquals(asList("good1", "good2", "good3"), response);
    assertEquals(6, response.readCount());
}
Also used : IFunction(com.hazelcast.core.IFunction) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

IFunction (com.hazelcast.core.IFunction)10 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 AtomicReferenceContainer (com.hazelcast.concurrent.atomicreference.AtomicReferenceContainer)4 NodeEngine (com.hazelcast.spi.NodeEngine)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Data (com.hazelcast.nio.serialization.Data)3 Employee (com.hazelcast.mapreduce.helpers.Employee)2 ReadResultSetImpl (com.hazelcast.ringbuffer.impl.ReadResultSetImpl)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1