Search in sources :

Example 21 with Node

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

the class InvocationFuture_GetNewInstanceTest method invocationToRemoteMember.

@Test
public void invocationToRemoteMember() throws ExecutionException, InterruptedException {
    Node localNode = getNode(local);
    Data response = localNode.nodeEngine.toData(new DummyObject());
    Operation op = new OperationWithResponse(response);
    Address remoteAddress = getAddress(remote);
    OperationService operationService = getOperationService(local);
    Future future = operationService.createInvocationBuilder(null, op, remoteAddress).invoke();
    Object instance1 = future.get();
    Object instance2 = future.get();
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertTrue(instance1 instanceof DummyObject);
    assertTrue(instance2 instanceof DummyObject);
    assertNotSame(instance1, instance2);
    assertNotSame(instance1, response);
    assertNotSame(instance2, response);
}
Also used : Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.nio.serialization.Data) Operation(com.hazelcast.spi.Operation) OperationService(com.hazelcast.spi.OperationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with Node

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

the class InvocationFuture_GetNewInstanceTest method invocationToLocalMember.

@Test
public void invocationToLocalMember() throws ExecutionException, InterruptedException {
    Node localNode = getNode(local);
    Data response = localNode.nodeEngine.toData(new DummyObject());
    Operation op = new OperationWithResponse(response);
    OperationService service = getOperationService(local);
    Future future = service.createInvocationBuilder(null, op, localNode.address).invoke();
    Object instance1 = future.get();
    Object instance2 = future.get();
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertTrue(instance1 instanceof DummyObject);
    assertTrue(instance2 instanceof DummyObject);
    assertNotSame(instance1, instance2);
    assertNotSame(instance1, response);
    assertNotSame(instance2, response);
}
Also used : Node(com.hazelcast.instance.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.nio.serialization.Data) Operation(com.hazelcast.spi.Operation) OperationService(com.hazelcast.spi.OperationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with Node

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

the class MapTransactionTest method testGetForUpdate_releasesBackupLock.

@Test
public void testGetForUpdate_releasesBackupLock() {
    Config config = getConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    final String keyOwnedByInstance2 = generateKeyOwnedBy(instance2);
    instance1.executeTransaction(new TransactionalTask<Object>() {

        @Override
        public Object execute(TransactionalTaskContext context) throws TransactionException {
            TransactionalMap<Object, Object> map = context.getMap(randomString());
            map.getForUpdate(keyOwnedByInstance2);
            return null;
        }
    });
    Node node = TestUtil.getNode(instance1);
    Data keyData = node.nodeEngine.toData(keyOwnedByInstance2);
    LockService lockService = node.nodeEngine.getService(LockService.SERVICE_NAME);
    for (LockResource lockResource : lockService.getAllLocks()) {
        if (keyData.equals(lockResource.getKey())) {
            assertEquals(0, lockResource.getLockCount());
        }
    }
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) LockService(com.hazelcast.concurrent.lock.LockService) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) Data(com.hazelcast.nio.serialization.Data) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) LockResource(com.hazelcast.concurrent.lock.LockResource) Mockito.anyObject(org.mockito.Mockito.anyObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with Node

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

the class IndexIntegrationTest method getIndexOfAttributeForMap.

private static 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);
    Indexes indexes = mapContainer.getIndexes();
    return indexes.getIndex(attribute);
}
Also used : Node(com.hazelcast.instance.Node) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 25 with Node

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

the class DiscoverySpiTest method testSPIAwareMemberGroupFactoryCreateMemberGroups.

@Test
public void testSPIAwareMemberGroupFactoryCreateMemberGroups() throws Exception {
    String xmlFileName = "test-hazelcast-discovery-spi-metadata.xml";
    Config config = getDiscoverySPIConfig(xmlFileName);
    // we create this instance in order to fully create Node
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    Node node = TestUtil.getNode(hazelcastInstance);
    assertNotNull(node);
    MemberGroupFactory groupFactory = new SPIAwareMemberGroupFactory(node.getDiscoveryService());
    Collection<Member> members = createMembers();
    Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
    assertEquals("Member Groups: " + String.valueOf(memberGroups), 2, memberGroups.size());
    for (MemberGroup memberGroup : memberGroups) {
        assertEquals("Member Group: " + String.valueOf(memberGroup), 2, memberGroup.size());
    }
    hazelcastInstance.shutdown();
}
Also used : DefaultMemberGroup(com.hazelcast.partition.membergroup.DefaultMemberGroup) MemberGroup(com.hazelcast.partition.membergroup.MemberGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Node(com.hazelcast.instance.Node) SPIAwareMemberGroupFactory(com.hazelcast.partition.membergroup.SPIAwareMemberGroupFactory) Member(com.hazelcast.core.Member) MemberGroupFactory(com.hazelcast.partition.membergroup.MemberGroupFactory) SPIAwareMemberGroupFactory(com.hazelcast.partition.membergroup.SPIAwareMemberGroupFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Node (com.hazelcast.instance.Node)131 HazelcastInstance (com.hazelcast.core.HazelcastInstance)60 Test (org.junit.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)45 ParallelTest (com.hazelcast.test.annotation.ParallelTest)42 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)21 ClientEventRegistration (com.hazelcast.client.spi.impl.listener.ClientEventRegistration)18 Address (com.hazelcast.nio.Address)17 Config (com.hazelcast.config.Config)14 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 ILogger (com.hazelcast.logging.ILogger)10 Data (com.hazelcast.nio.serialization.Data)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)10 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)9 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 SerializationService (com.hazelcast.spi.serialization.SerializationService)7 ItemListener (com.hazelcast.core.ItemListener)6 Operation (com.hazelcast.spi.Operation)6