Search in sources :

Example 26 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class QueryCacheEventLostListenerTest method setTestSequencer.

private void setTestSequencer(HazelcastInstance instance, int eventCount) {
    Node node = getNode(instance);
    MapService service = node.getNodeEngine().getService(MapService.SERVICE_NAME);
    MapServiceContext mapServiceContext = service.getMapServiceContext();
    QueryCacheContext queryCacheContext = mapServiceContext.getQueryCacheContext();
    queryCacheContext.setSubscriberContext(new TestSubscriberContext(queryCacheContext, eventCount, true));
}
Also used : TestSubscriberContext(com.hazelcast.map.impl.querycache.subscriber.TestSubscriberContext) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 27 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class HazelcastStarterTest method testHazelcastInstanceCompatibility.

private static void testHazelcastInstanceCompatibility(HazelcastInstance instance, TestHazelcastInstanceFactory factory) {
    Node node = TestUtil.getNode(instance);
    HazelcastInstanceImpl instanceImpl = TestUtil.getHazelcastInstanceImpl(instance);
    if (factory != null) {
        assertEquals("Expected one active HazelcastInstance in the factory", 1, factory.getAllHazelcastInstances().size());
    }
    assertNode(node, true);
    assertHazelcastInstanceImpl(instanceImpl);
    assertSafePartitionServiceState(instance);
    instance.shutdown();
    assertNode(node, false);
    if (factory != null) {
        assertEquals("Expected no active HazelcastInstances in the factory", 0, factory.getAllHazelcastInstances().size());
    }
    assertGetNodeFromShutdownInstance(instance);
    assertGetHazelcastInstanceImplFromShutdownInstance(instance);
    assertSafePartitionServiceState(instance);
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) Node(com.hazelcast.instance.impl.Node)

Example 28 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class HazelcastStarterTest method testMemberWithConfig.

private void testMemberWithConfig(String version, boolean supportsFirewallingConnectionManager) {
    Config config = new Config().setInstanceName("test-name");
    hz = HazelcastStarter.newHazelcastInstance(version, config, false);
    assertEquals(hz.getName(), "test-name");
    Node node = HazelcastStarter.getNode(hz);
    assertNotNull(node);
    assertEquals("Expected the same address from HazelcastInstance and Node", hz.getCluster().getLocalMember().getAddress(), node.getThisAddress());
    if (supportsFirewallingConnectionManager) {
        assertInstanceOf(FirewallingServer.class, node.getServer());
    } else {
        assertInstanceOf(TcpServer.class, node.getServer());
    }
}
Also used : Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.impl.Node)

Example 29 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class CacheManagerAnswer method answer.

@Override
Object answer(InvocationOnMock invocation, String methodName, Object[] arguments) throws Exception {
    if (arguments.length == 1 && methodName.equals("getCacheByFullName")) {
        String cacheName = (String) arguments[0];
        Object original = getFieldValueReflectively(delegate, "original");
        Object delegateNode = getFieldValueReflectively(original, "node");
        Node node = mock(Node.class, new NodeAnswer(delegateNode));
        NodeEngine nodeEngine = node.getNodeEngine();
        CacheConfig cacheConfig = new CacheConfig(node.getConfig().getCacheConfig(cacheName));
        CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
        // we have to create the mock with useConstructor(), otherwise the
        // calls to the AbstractDistributedObject (its base class) won't
        // work properly, since the NodeEngine field is not set (final
        // method calls are not mocked in the used Mockito version)
        Object cacheProxy = invokeForMock(invocation, arguments);
        return mock(CacheProxy.class, withSettings().useConstructor(cacheConfig, nodeEngine, cacheService).defaultAnswer(new CacheProxyAnswer(cacheProxy)));
    } else if (arguments.length == 0) {
        return invoke(invocation);
    }
    throw new UnsupportedOperationException("Method is not implemented in CacheManagerAnswer: " + methodName);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Node(com.hazelcast.instance.impl.Node) CacheConfig(com.hazelcast.config.CacheConfig) CacheService(com.hazelcast.cache.impl.CacheService)

Example 30 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class MapIndexJsonTest method getIndexOfAttributeForMap.

protected static List<Index> getIndexOfAttributeForMap(HazelcastInstance instance, String mapName, String attribute) {
    Node node = getNode(instance);
    MapService service = node.nodeEngine.getService(MapService.SERVICE_NAME);
    MapServiceContext mapServiceContext = service.getMapServiceContext();
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    List<Index> result = new ArrayList<>();
    for (int partitionId : mapServiceContext.getOrInitCachedMemberPartitions()) {
        Indexes indexes = mapContainer.getIndexes(partitionId);
        result.add(indexes.getIndex(attribute));
    }
    return result;
}
Also used : Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) ArrayList(java.util.ArrayList) Index(com.hazelcast.query.impl.Index) MapService(com.hazelcast.map.impl.MapService) Indexes(com.hazelcast.query.impl.Indexes) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Aggregations

Node (com.hazelcast.instance.impl.Node)144 Accessors.getNode (com.hazelcast.test.Accessors.getNode)84 HazelcastInstance (com.hazelcast.core.HazelcastInstance)68 Test (org.junit.Test)60 QuickTest (com.hazelcast.test.annotation.QuickTest)57 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)44 Config (com.hazelcast.config.Config)22 Address (com.hazelcast.cluster.Address)20 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)19 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 UUID (java.util.UUID)13 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)12 SerializationService (com.hazelcast.internal.serialization.SerializationService)12 ILogger (com.hazelcast.logging.ILogger)10 MapService (com.hazelcast.map.impl.MapService)10 ClientConnectionRegistration (com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration)9 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 HashMap (java.util.HashMap)9 Data (com.hazelcast.internal.serialization.Data)8 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)8