Search in sources :

Example 46 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class TcpIpConnection_AbstractTest method setup.

@Before
public void setup() throws Exception {
    addressA = new Address("127.0.0.1", 5701);
    addressB = new Address("127.0.0.1", 5702);
    addressC = new Address("127.0.0.1", 5703);
    loggingService = new LoggingServiceImpl("somegroup", "log4j2", BuildInfoProvider.BUILD_INFO);
    logger = loggingService.getLogger(TcpIpConnection_AbstractTest.class);
    metricsRegistryA = newMetricsRegistry();
    connManagerA = newConnectionManager(addressA.getPort(), metricsRegistryA);
    ioServiceA = (MockIOService) connManagerA.getIoService();
    metricsRegistryB = newMetricsRegistry();
    connManagerB = newConnectionManager(addressB.getPort(), metricsRegistryB);
    ioServiceB = (MockIOService) connManagerB.getIoService();
    metricsRegistryC = newMetricsRegistry();
    connManagerC = newConnectionManager(addressC.getPort(), metricsRegistryC);
    ioServiceC = (MockIOService) connManagerB.getIoService();
    serializationService = (InternalSerializationService) new DefaultSerializationServiceBuilder().addDataSerializableFactory(TestDataFactory.FACTORY_ID, new TestDataFactory()).build();
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SocketAddress(java.net.SocketAddress) Address(com.hazelcast.nio.Address) LoggingServiceImpl(com.hazelcast.logging.LoggingServiceImpl) Before(org.junit.Before)

Example 47 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class OperationServiceImpl_timeoutTest method testOperationTimeoutForLongRunningRemoteOperation.

@Test
public void testOperationTimeoutForLongRunningRemoteOperation() throws Exception {
    int callTimeoutMillis = 3000;
    Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "" + callTimeoutMillis);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    // invoke on the "remote" member
    Address remoteAddress = getNode(hz2).getThisAddress();
    OperationService operationService = getNode(hz1).getNodeEngine().getOperationService();
    ICompletableFuture<Boolean> future = operationService.invokeOnTarget(null, new SleepingOperation(callTimeoutMillis * 5), remoteAddress);
    // wait more than operation timeout
    sleepAtLeastMillis(callTimeoutMillis * 3);
    assertTrue(future.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Config(com.hazelcast.config.Config) 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 48 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method checkTestResult.

private void checkTestResult(Address[][] state, Collection<MemberGroup> groups, int partitionCount) {
    Iterator<MemberGroup> iter = groups.iterator();
    while (iter.hasNext()) {
        if (iter.next().size() == 0) {
            iter.remove();
        }
    }
    int replicaCount = Math.min(groups.size(), InternalPartition.MAX_REPLICA_COUNT);
    Map<MemberGroup, GroupPartitionState> groupPartitionStates = new HashMap<MemberGroup, GroupPartitionState>();
    Set<Address> set = new HashSet<Address>();
    int avgPartitionPerGroup = partitionCount / groups.size();
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        Address[] replicas = state[partitionId];
        for (int i = 0; i < replicaCount; i++) {
            Address owner = replicas[i];
            assertNotNull(owner);
            assertFalse("Duplicate owner of partition: " + partitionId, set.contains(owner));
            set.add(owner);
            MemberGroup group = null;
            for (MemberGroup g : groups) {
                if (g.hasMember(new MemberImpl(owner, VERSION, true))) {
                    group = g;
                    break;
                }
            }
            assertNotNull(group);
            GroupPartitionState groupState = groupPartitionStates.get(group);
            if (groupState == null) {
                groupState = new GroupPartitionState();
                groupState.group = group;
                groupPartitionStates.put(group, groupState);
            }
            groupState.groupPartitions[i].add(partitionId);
            groupState.getNodePartitions(owner)[i].add(partitionId);
        }
        set.clear();
    }
    for (GroupPartitionState groupState : groupPartitionStates.values()) {
        for (Map.Entry<Address, Set<Integer>[]> entry : groupState.nodePartitionsMap.entrySet()) {
            Collection<Integer>[] partitions = entry.getValue();
            for (int i = 0; i < replicaCount; i++) {
                int avgPartitionPerNode = groupState.groupPartitions[i].size() / groupState.nodePartitionsMap.size();
                int count = partitions[i].size();
                isInAllowedRange(count, avgPartitionPerNode, i, entry.getKey(), groups, partitionCount);
            }
        }
        Collection<Integer>[] partitions = groupState.groupPartitions;
        for (int i = 0; i < replicaCount; i++) {
            int count = partitions[i].size();
            isInAllowedRange(count, avgPartitionPerGroup, i, groupState.group, groups, partitionCount);
        }
    }
    printTable(groupPartitionStates, replicaCount);
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.instance.MemberImpl) DefaultMemberGroup(com.hazelcast.partition.membergroup.DefaultMemberGroup) MemberGroup(com.hazelcast.partition.membergroup.MemberGroup) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 49 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class MigrationPlannerTest method shuffle.

private void shuffle(Address[] array, int len) {
    int index;
    Address temp;
    Random random = new Random();
    for (int i = len - 1; i > 0; i--) {
        index = random.nextInt(i + 1);
        temp = array[index];
        array[index] = array[i];
        array[i] = temp;
    }
}
Also used : Address(com.hazelcast.nio.Address) Random(java.util.Random)

Example 50 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class MemberGroupFactoryTest method createMembersWithHostAwareMetadata.

private Collection<Member> createMembersWithHostAwareMetadata() throws UnknownHostException {
    Collection<Member> members = new HashSet<Member>();
    InetAddress fakeAddress = InetAddress.getLocalHost();
    MemberImpl member1 = new MemberImpl(new Address("192.192.0.1", fakeAddress, 5701), VERSION, true);
    member1.setStringAttribute(PartitionGroupMetaData.PARTITION_GROUP_HOST, "host-1");
    MemberImpl member2 = new MemberImpl(new Address("192.192.0.2", fakeAddress, 5701), VERSION, true);
    member2.setStringAttribute(PartitionGroupMetaData.PARTITION_GROUP_HOST, "host-2");
    MemberImpl member3 = new MemberImpl(new Address("192.192.0.3", fakeAddress, 5701), VERSION, true);
    member3.setStringAttribute(PartitionGroupMetaData.PARTITION_GROUP_HOST, "host-3");
    members.add(member1);
    members.add(member2);
    members.add(member3);
    return members;
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet)

Aggregations

Address (com.hazelcast.nio.Address)274 Test (org.junit.Test)44 QuickTest (com.hazelcast.test.annotation.QuickTest)36 HashMap (java.util.HashMap)33 ParallelTest (com.hazelcast.test.annotation.ParallelTest)29 Member (com.hazelcast.core.Member)27 ArrayList (java.util.ArrayList)27 Map (java.util.Map)26 ILogger (com.hazelcast.logging.ILogger)25 InetAddress (java.net.InetAddress)25 MemberImpl (com.hazelcast.instance.MemberImpl)21 List (java.util.List)20 HashSet (java.util.HashSet)18 Connection (com.hazelcast.nio.Connection)17 NodeEngine (com.hazelcast.spi.NodeEngine)16 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 IOException (java.io.IOException)16 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 IPartitionService (com.hazelcast.spi.partition.IPartitionService)13