Search in sources :

Example 1 with HazelcastInstanceProxy

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

the class CacheClearTest method registerInvalidationListener.

private void registerInvalidationListener(CacheEventListener cacheEventListener, String name) {
    HazelcastInstanceProxy hzInstance = (HazelcastInstanceProxy) this.hazelcastInstance;
    hzInstance.getOriginal().node.getNodeEngine().getEventService().registerListener(ICacheService.SERVICE_NAME, name, cacheEventListener);
}
Also used : HazelcastInstanceProxy(com.hazelcast.instance.HazelcastInstanceProxy)

Example 2 with HazelcastInstanceProxy

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

the class DefaultPortableReaderSpecTest method reader.

//
// Hazelcast init Utilities
//
public PortableReader reader(Portable portable) throws IOException {
    Config config = new Config();
    config.getSerializationConfig().addPortableFactory(TestPortableFactory.ID, new TestPortableFactory());
    HazelcastInstanceProxy hz = (HazelcastInstanceProxy) createHazelcastInstance(config);
    IMap<String, Object> map = hz.getMap("stealingMap");
    // avoid the case where there's no class definition
    if (portable instanceof PrimitivePortable) {
        map.put(P_NON_EMPTY.toString(), P_NON_EMPTY);
    }
    if (portable instanceof GroupPortable) {
        map.put(G_NON_EMPTY.toString(), G_NON_EMPTY);
    }
    if (portable instanceof NestedGroupPortable) {
        map.put(N_NON_EMPTY.toString(), N_NON_EMPTY);
    }
    map.put(portable.toString(), portable);
    EntryStealingProcessor processor = new EntryStealingProcessor(portable.toString());
    map.executeOnEntries(processor);
    SerializationServiceV1 ss = (SerializationServiceV1) hz.getSerializationService();
    return ss.createPortableReader(processor.stolenEntryData);
}
Also used : TestPortableFactory(com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.TestPortableFactory) Config(com.hazelcast.config.Config) PrimitivePortable(com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.PrimitivePortable) NestedGroupPortable(com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.NestedGroupPortable) SerializationServiceV1(com.hazelcast.internal.serialization.impl.SerializationServiceV1) HazelcastInstanceProxy(com.hazelcast.instance.HazelcastInstanceProxy) GroupPortable(com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.GroupPortable) NestedGroupPortable(com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.NestedGroupPortable)

Example 3 with HazelcastInstanceProxy

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

the class DefaultPortableReaderQuickTest method reader.

//
// Utilities
//
public PortableReader reader(Portable portable) throws IOException {
    Config config = new Config();
    config.getSerializationConfig().addPortableFactory(TestPortableFactory.ID, new TestPortableFactory());
    HazelcastInstanceProxy hz = (HazelcastInstanceProxy) createHazelcastInstance(config);
    IMap<String, Object> map = hz.getMap("stealingMap");
    if (portable instanceof CarPortable) {
        // makes sure that proper class definitions are registered
        map.put(NON_EMPTY_PORSCHE.toString(), NON_EMPTY_PORSCHE);
    }
    map.put(portable.toString(), portable);
    EntryStealingProcessor processor = new EntryStealingProcessor(portable.toString());
    map.executeOnEntries(processor);
    SerializationServiceV1 ss = (SerializationServiceV1) hz.getSerializationService();
    return ss.createPortableReader(processor.stolenEntryData);
}
Also used : Config(com.hazelcast.config.Config) SerializationServiceV1(com.hazelcast.internal.serialization.impl.SerializationServiceV1) HazelcastInstanceProxy(com.hazelcast.instance.HazelcastInstanceProxy)

Example 4 with HazelcastInstanceProxy

use of com.hazelcast.instance.HazelcastInstanceProxy 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)

Example 5 with HazelcastInstanceProxy

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

the class CacheSerializationTest method test_CacheReplicationOperation_serialization.

@Test
public void test_CacheReplicationOperation_serialization() throws Exception {
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
    try {
        CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(hazelcastInstance);
        CacheManager manager = provider.getCacheManager();
        CompleteConfiguration configuration = new MutableConfiguration();
        Cache cache1 = manager.createCache("cache1", configuration);
        Cache cache2 = manager.createCache("cache2", configuration);
        Cache cache3 = manager.createCache("cache3", configuration);
        for (int i = 0; i < 1000; i++) {
            cache1.put("key" + i, i);
            cache2.put("key" + i, i);
            cache3.put("key" + i, i);
        }
        HazelcastInstanceProxy proxy = (HazelcastInstanceProxy) hazelcastInstance;
        Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
        original.setAccessible(true);
        HazelcastInstanceImpl impl = (HazelcastInstanceImpl) original.get(proxy);
        NodeEngineImpl nodeEngine = impl.node.nodeEngine;
        CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
        int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
        for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
            CachePartitionSegment segment = cacheService.getSegment(partitionId);
            CacheReplicationOperation operation = new CacheReplicationOperation(segment, 1);
            Data serialized = service.toData(operation);
            try {
                service.toObject(serialized);
            } catch (Exception e) {
                throw new Exception("Partition: " + partitionId, e);
            }
        }
    } finally {
        factory.shutdownAll();
    }
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CachePartitionSegment(com.hazelcast.cache.impl.CachePartitionSegment) CacheReplicationOperation(com.hazelcast.cache.impl.operation.CacheReplicationOperation) Data(com.hazelcast.nio.serialization.Data) CachePartitionEventData(com.hazelcast.cache.impl.CachePartitionEventData) HazelcastInstanceProxy(com.hazelcast.instance.HazelcastInstanceProxy) MutableConfiguration(javax.cache.configuration.MutableConfiguration) UnknownHostException(java.net.UnknownHostException) Field(java.lang.reflect.Field) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) CacheManager(javax.cache.CacheManager) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) CacheService(com.hazelcast.cache.impl.CacheService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstanceProxy (com.hazelcast.instance.HazelcastInstanceProxy)6 Config (com.hazelcast.config.Config)2 HazelcastInstanceImpl (com.hazelcast.instance.HazelcastInstanceImpl)2 SerializationServiceV1 (com.hazelcast.internal.serialization.impl.SerializationServiceV1)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Field (java.lang.reflect.Field)2 Test (org.junit.Test)2 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 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ITopic (com.hazelcast.core.ITopic)1 MemberImpl (com.hazelcast.instance.MemberImpl)1 Address (com.hazelcast.nio.Address)1 Data (com.hazelcast.nio.serialization.Data)1 GroupPortable (com.hazelcast.nio.serialization.impl.DefaultPortableReaderTestStructure.GroupPortable)1