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();
}
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());
}
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);
}
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;
}
}
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;
}
Aggregations