Search in sources :

Example 1 with PartitionOperationThread

use of com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread in project hazelcast by hazelcast.

the class InterceptorRegistryTest method testDeregister_fromPartitionOperationThread.

@Test
@RequireAssertEnabled
public void testDeregister_fromPartitionOperationThread() throws Exception {
    OperationQueue queue = new DefaultOperationQueue();
    PartitionOperationThread thread = getPartitionOperationThread(queue);
    thread.start();
    registry.register(interceptor.id, interceptor);
    final CountDownLatch latch = new CountDownLatch(1);
    Object task = new Runnable() {

        @Override
        public void run() {
            try {
                registry.deregister(interceptor.id);
            } catch (AssertionError e) {
                e.printStackTrace();
                latch.countDown();
            }
        }
    };
    queue.add(task, false);
    latch.await();
    thread.shutdown();
    thread.join();
    assertInterceptorRegistryContainsInterceptor();
}
Also used : DefaultOperationQueue(com.hazelcast.spi.impl.operationexecutor.impl.DefaultOperationQueue) OperationQueue(com.hazelcast.spi.impl.operationexecutor.impl.OperationQueue) PartitionOperationThread(com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultOperationQueue(com.hazelcast.spi.impl.operationexecutor.impl.DefaultOperationQueue) RequireAssertEnabled(com.hazelcast.test.RequireAssertEnabled) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with PartitionOperationThread

use of com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread in project hazelcast by hazelcast.

the class InterceptorRegistryTest method getPartitionOperationThread.

private PartitionOperationThread getPartitionOperationThread(OperationQueue queue) {
    HazelcastThreadGroup threadGroup = new HazelcastThreadGroup("instanceName", LOGGER, getClass().getClassLoader());
    NodeExtension nodeExtension = mock(NodeExtension.class);
    OperationRunner operationRunner = mock(OperationRunner.class);
    OperationRunner[] operationRunners = new OperationRunner[] { operationRunner };
    return new PartitionOperationThread("threadName", 0, queue, LOGGER, threadGroup, nodeExtension, operationRunners);
}
Also used : PartitionOperationThread(com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread) OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner) HazelcastThreadGroup(com.hazelcast.instance.HazelcastThreadGroup) NodeExtension(com.hazelcast.instance.NodeExtension)

Example 3 with PartitionOperationThread

use of com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread in project hazelcast by hazelcast.

the class InterceptorRegistry method deregister.

/**
     * De-registers {@link MapInterceptor} for the supplied `id`, if there is any.
     *
     * This method is called by {@link com.hazelcast.spi.impl.operationexecutor.impl.GenericOperationThread}
     * when de-registering via {@link com.hazelcast.map.impl.operation.RemoveInterceptorOperation}
     *
     * @param id id of the interceptor
     */
public synchronized void deregister(String id) {
    assert !(Thread.currentThread() instanceof PartitionOperationThread);
    if (!id2InterceptorMap.containsKey(id)) {
        return;
    }
    Map<String, MapInterceptor> tmpMap = new HashMap<String, MapInterceptor>(id2InterceptorMap);
    MapInterceptor removedInterceptor = tmpMap.remove(id);
    id2InterceptorMap = unmodifiableMap(tmpMap);
    List<MapInterceptor> tmpInterceptors = new ArrayList<MapInterceptor>(interceptors);
    tmpInterceptors.remove(removedInterceptor);
    interceptors = unmodifiableList(tmpInterceptors);
}
Also used : PartitionOperationThread(com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread) HashMap(java.util.HashMap) MapInterceptor(com.hazelcast.map.MapInterceptor) ArrayList(java.util.ArrayList)

Example 4 with PartitionOperationThread

use of com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread in project hazelcast by hazelcast.

the class InterceptorRegistryTest method testRegister_fromPartitionOperationThread.

@Test
@RequireAssertEnabled
public void testRegister_fromPartitionOperationThread() throws Exception {
    OperationQueue queue = new DefaultOperationQueue();
    PartitionOperationThread thread = getPartitionOperationThread(queue);
    thread.start();
    final CountDownLatch latch = new CountDownLatch(1);
    Object task = new Runnable() {

        @Override
        public void run() {
            try {
                registry.register(interceptor.id, interceptor);
            } catch (AssertionError e) {
                e.printStackTrace();
                latch.countDown();
            }
        }
    };
    queue.add(task, false);
    latch.await();
    thread.shutdown();
    thread.join();
    assertInterceptorRegistryContainsNotInterceptor();
}
Also used : DefaultOperationQueue(com.hazelcast.spi.impl.operationexecutor.impl.DefaultOperationQueue) OperationQueue(com.hazelcast.spi.impl.operationexecutor.impl.OperationQueue) PartitionOperationThread(com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultOperationQueue(com.hazelcast.spi.impl.operationexecutor.impl.DefaultOperationQueue) RequireAssertEnabled(com.hazelcast.test.RequireAssertEnabled) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

PartitionOperationThread (com.hazelcast.spi.impl.operationexecutor.impl.PartitionOperationThread)4 DefaultOperationQueue (com.hazelcast.spi.impl.operationexecutor.impl.DefaultOperationQueue)2 OperationQueue (com.hazelcast.spi.impl.operationexecutor.impl.OperationQueue)2 RequireAssertEnabled (com.hazelcast.test.RequireAssertEnabled)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 HazelcastThreadGroup (com.hazelcast.instance.HazelcastThreadGroup)1 NodeExtension (com.hazelcast.instance.NodeExtension)1 MapInterceptor (com.hazelcast.map.MapInterceptor)1 OperationRunner (com.hazelcast.spi.impl.operationexecutor.OperationRunner)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1