Search in sources :

Example 6 with HazelcastInstanceImpl

use of com.hazelcast.instance.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class CacheEntryProcessorTest method setUpInternal.

private static void setUpInternal() throws NoSuchFieldException, IllegalAccessException {
    factory = new TestHazelcastInstanceFactory(2);
    node1 = factory.newHazelcastInstance();
    node2 = factory.newHazelcastInstance();
    Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
    original.setAccessible(true);
    HazelcastInstanceImpl impl1 = (HazelcastInstanceImpl) original.get(node1);
    HazelcastInstanceImpl impl2 = (HazelcastInstanceImpl) original.get(node2);
    cacheServiceOnNode1 = impl1.node.getNodeEngine().getService(CacheService.SERVICE_NAME);
    cacheServiceOnNode2 = impl2.node.getNodeEngine().getService(CacheService.SERVICE_NAME);
    serializationService = impl1.node.getNodeEngine().getSerializationService();
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) Field(java.lang.reflect.Field) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 7 with HazelcastInstanceImpl

use of com.hazelcast.instance.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class MapRemoveFailingBackupTest method testMapRemoveFailingBackupShouldNotLeadToStaleDataWhenReadBackupIsEnabled.

@Test
public void testMapRemoveFailingBackupShouldNotLeadToStaleDataWhenReadBackupIsEnabled() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final String mapName = randomMapName();
    final String key = "2";
    final String value = "value2";
    Config config = getConfig();
    config.getSerializationConfig().addDataSerializableFactory(100, new Factory());
    config.setProperty(GroupProperty.PARTITION_BACKUP_SYNC_INTERVAL.getName(), "5");
    config.getMapConfig(mapName).setReadBackupData(true);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    final HazelcastInstanceImpl hz1Impl = TestUtil.getHazelcastInstanceImpl(hz1);
    final IMap<Object, Object> map1 = hz1.getMap(mapName);
    final IMap<Object, Object> map2 = hz2.getMap(mapName);
    MapProxyImpl<Object, Object> mock1 = (MapProxyImpl<Object, Object>) spy(map1);
    when(mock1.remove(anyString())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            NodeEngineImpl nodeEngine = hz1Impl.node.nodeEngine;
            Object object = invocation.getArguments()[0];
            final Data key = nodeEngine.toData(object);
            RemoveOperation operation = new RemoveOperation(mapName, key);
            int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
            operation.setThreadId(ThreadUtil.getThreadId());
            OperationService operationService = nodeEngine.getOperationService();
            InternalCompletableFuture<Data> f = operationService.createInvocationBuilder(SERVICE_NAME, operation, partitionId).setResultDeserialized(false).invoke();
            Data result = f.get();
            return nodeEngine.toObject(result);
        }
    });
    mock1.put(key, value);
    mock1.remove(key);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNull(map1.get(key));
            assertNull(map2.get(key));
        }
    }, 30);
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) BaseRemoveOperation(com.hazelcast.map.impl.operation.BaseRemoveOperation) Data(com.hazelcast.nio.serialization.Data) Matchers.anyString(org.mockito.Matchers.anyString) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with HazelcastInstanceImpl

use of com.hazelcast.instance.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class OperationServiceImpl_BasicTest method testPropagateSerializationErrorOnResponseToCallerGithubIssue2559.

@Test(expected = ExecutionException.class)
public void testPropagateSerializationErrorOnResponseToCallerGithubIssue2559() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz1 = factory.newHazelcastInstance();
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
    original.setAccessible(true);
    HazelcastInstanceImpl impl = (HazelcastInstanceImpl) original.get(hz1);
    OperationService operationService = impl.node.nodeEngine.getOperationService();
    Address address = hz2.getCluster().getLocalMember().getAddress();
    Operation operation = new GithubIssue2559Operation();
    String serviceName = DistributedExecutorService.SERVICE_NAME;
    InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(serviceName, operation, address);
    invocationBuilder.invoke().get();
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) Field(java.lang.reflect.Field) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) OperationService(com.hazelcast.spi.OperationService) Operation(com.hazelcast.spi.Operation) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with HazelcastInstanceImpl

use of com.hazelcast.instance.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class EventServiceTest method testEventService.

@Test(timeout = 90000)
public void testEventService() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstanceProxy h1 = (HazelcastInstanceProxy) factory.newHazelcastInstance();
    HazelcastInstanceProxy h2 = (HazelcastInstanceProxy) factory.newHazelcastInstance();
    HazelcastInstanceProxy h3 = (HazelcastInstanceProxy) factory.newHazelcastInstance();
    CountDownLatch l1 = new CountDownLatch(1000);
    CountDownLatch l2 = new CountDownLatch(1000);
    CountDownLatch l3 = new CountDownLatch(1000);
    ITopic t1 = h1.getTopic("foo");
    ITopic t2 = h2.getTopic("foo");
    ITopic t3 = h3.getTopic("foo");
    t1.addMessageListener(createMessageListener(l1));
    t2.addMessageListener(createMessageListener(l2));
    t3.addMessageListener(createMessageListener(l3));
    MemberImpl m1 = (MemberImpl) h1.getCluster().getLocalMember();
    MemberImpl m2 = (MemberImpl) h2.getCluster().getLocalMember();
    MemberImpl m3 = (MemberImpl) h3.getCluster().getLocalMember();
    Address a1 = m1.getAddress();
    Address a2 = m2.getAddress();
    Address a3 = m3.getAddress();
    Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
    original.setAccessible(true);
    HazelcastInstanceImpl impl1 = (HazelcastInstanceImpl) original.get(h1);
    HazelcastInstanceImpl impl2 = (HazelcastInstanceImpl) original.get(h2);
    HazelcastInstanceImpl impl3 = (HazelcastInstanceImpl) original.get(h3);
    EventService es1 = impl1.node.nodeEngine.getEventService();
    EventService es2 = impl2.node.nodeEngine.getEventService();
    EventService es3 = impl3.node.nodeEngine.getEventService();
    SerializationService ss1 = impl1.node.nodeEngine.getSerializationService();
    SerializationService ss2 = impl2.node.nodeEngine.getSerializationService();
    SerializationService ss3 = impl3.node.nodeEngine.getSerializationService();
    int counter = 0;
    for (int i = 0; i < 3000; i++) {
        if (counter == 0) {
            TopicEvent event = builTopicEvent("Foo" + i, m1, ss1);
            Collection<EventRegistration> registrations = es1.getRegistrations(TopicService.SERVICE_NAME, "foo");
            EventRegistration registration = findEventRegistration(a3, registrations);
            es1.publishEvent(TopicService.SERVICE_NAME, registration, event, 0);
        } else if (counter == 1) {
            TopicEvent event = builTopicEvent("Foo" + i, m2, ss2);
            Collection<EventRegistration> registrations = es2.getRegistrations(TopicService.SERVICE_NAME, "foo");
            EventRegistration registration = findEventRegistration(a1, registrations);
            es2.publishEvent(TopicService.SERVICE_NAME, registration, event, 0);
        } else if (counter == 2) {
            TopicEvent event = builTopicEvent("Foo" + i, m3, ss3);
            Collection<EventRegistration> registrations = es3.getRegistrations(TopicService.SERVICE_NAME, "foo");
            EventRegistration registration = findEventRegistration(a2, registrations);
            es3.publishEvent(TopicService.SERVICE_NAME, registration, event, 0);
        }
        counter++;
        if (counter == 3)
            counter = 0;
    }
    l1.await(30, TimeUnit.SECONDS);
    l2.await(30, TimeUnit.SECONDS);
    l3.await(30, TimeUnit.SECONDS);
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) TopicEvent(com.hazelcast.topic.impl.TopicEvent) ITopic(com.hazelcast.core.ITopic) EventRegistration(com.hazelcast.spi.EventRegistration) Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) SerializationService(com.hazelcast.spi.serialization.SerializationService) EventService(com.hazelcast.spi.EventService) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstanceProxy(com.hazelcast.instance.HazelcastInstanceProxy) Field(java.lang.reflect.Field) Collection(java.util.Collection) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstanceImpl (com.hazelcast.instance.HazelcastInstanceImpl)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 Field (java.lang.reflect.Field)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 HazelcastInstanceProxy (com.hazelcast.instance.HazelcastInstanceProxy)2 Address (com.hazelcast.nio.Address)2 Data (com.hazelcast.nio.serialization.Data)2 Operation (com.hazelcast.spi.Operation)2 OperationService (com.hazelcast.spi.OperationService)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 SerializationService (com.hazelcast.spi.serialization.SerializationService)2 JsonObject (com.eclipsesource.json.JsonObject)1 CachePartitionEventData (com.hazelcast.cache.impl.CachePartitionEventData)1 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)1 CacheService (com.hazelcast.cache.impl.CacheService)1 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 CacheReplicationOperation (com.hazelcast.cache.impl.operation.CacheReplicationOperation)1