use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class IOBalancerMemoryLeakTest method testMemoryLeak_with_SocketConnections.
@Test
public void testMemoryLeak_with_SocketConnections() throws IOException {
Config config = new Config();
config.getGroupConfig().setName(randomName());
config.setProperty(GroupProperty.IO_BALANCER_INTERVAL_SECONDS.getName(), "1");
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
final Address address = instance.getCluster().getLocalMember().getAddress();
int threadCount = 10;
final int connectionCountPerThread = 100;
Runnable runnable = new Runnable() {
public void run() {
for (int i = 0; i < connectionCountPerThread; i++) {
Socket socket = null;
try {
socket = new Socket(address.getHost(), address.getPort());
socket.getOutputStream().write(Protocols.CLUSTER.getBytes());
sleepMillis(1000);
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
threads[i] = new Thread(runnable);
threads[i].start();
}
assertJoinable(threads);
TcpIpConnectionManager connectionManager = (TcpIpConnectionManager) getConnectionManager(instance);
final IOBalancer ioBalancer = connectionManager.getIoBalancer();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
LoadTracker inLoadTracker = ioBalancer.getInLoadTracker();
LoadTracker outLoadTracker = ioBalancer.getOutLoadTracker();
int inHandlerSize = inLoadTracker.getHandlers().size();
int outHandlerSize = outLoadTracker.getHandlers().size();
int inHandlerEventsCount = inLoadTracker.getHandlerEventsCounter().keySet().size();
int outHandlerEventsCount = outLoadTracker.getHandlerEventsCounter().keySet().size();
int inLastEventsCount = inLoadTracker.getLastEventCounter().keySet().size();
int outLastEventsCount = outLoadTracker.getLastEventCounter().keySet().size();
Assert.assertEquals(0, inHandlerSize);
Assert.assertEquals(0, outHandlerSize);
Assert.assertEquals(0, inHandlerEventsCount);
Assert.assertEquals(0, outHandlerEventsCount);
Assert.assertEquals(0, inLastEventsCount);
Assert.assertEquals(0, outLastEventsCount);
}
});
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class MigrationCommitServiceTest method createShiftDownMigration.
private MigrationInfo createShiftDownMigration(int partitionId, int oldReplicaIndex, int newReplicaIndex, Address destination) {
InternalPartitionImpl partition = getPartition(instances[0], partitionId);
Address source = partition.getReplicaAddress(oldReplicaIndex);
String sourceUuid = getMemberUuid(source);
String destinationUuid = getMemberUuid(destination);
return new MigrationInfo(partitionId, source, sourceUuid, destination, destinationUuid, oldReplicaIndex, newReplicaIndex, -1, oldReplicaIndex);
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class AbstractPartitionAssignmentsCorrectnessTest method assertPartitionAssignments.
static void assertPartitionAssignments(TestHazelcastInstanceFactory factory) {
Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
final int replicaCount = Math.min(instances.size(), InternalPartition.MAX_REPLICA_COUNT);
for (HazelcastInstance hz : instances) {
Node node = getNode(hz);
InternalPartitionService partitionService = node.getPartitionService();
InternalPartition[] partitions = partitionService.getInternalPartitions();
for (InternalPartition partition : partitions) {
for (int i = 0; i < replicaCount; i++) {
Address replicaAddress = partition.getReplicaAddress(i);
assertNotNull("Replica " + i + " is not found in " + partition, replicaAddress);
assertTrue("Not member: " + replicaAddress, node.getClusterService().getMember(replicaAddress) != null);
}
}
}
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class LocalMapStatsTest method testHits_whenMultipleNodes.
@Test
public void testHits_whenMultipleNodes() throws InterruptedException {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance[] instances = factory.newInstances(getConfig());
MultiMap<Object, Object> multiMap0 = instances[0].getMultiMap("testHits_whenMultipleNodes");
MultiMap<Object, Object> multiMap1 = instances[1].getMultiMap("testHits_whenMultipleNodes");
// InternalPartitionService is used in order to determine owners of these keys that we will use.
InternalPartitionService partitionService = getNode(instances[0]).getPartitionService();
Address address = partitionService.getPartitionOwner(partitionService.getPartitionId("test1"));
boolean inFirstInstance = address.equals(getNode(instances[0]).getThisAddress());
multiMap0.get("test0");
multiMap0.put("test1", 1);
multiMap1.get("test1");
assertEquals(inFirstInstance ? 1 : 0, multiMap0.getLocalMultiMapStats().getHits());
assertEquals(inFirstInstance ? 0 : 1, multiMap1.getLocalMultiMapStats().getHits());
multiMap0.get("test1");
multiMap1.get("test1");
assertEquals(inFirstInstance ? 0 : 3, multiMap1.getLocalMultiMapStats().getHits());
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class JobPartitionStateImplTest method setUp.
@Before
public void setUp() throws Exception {
address = new Address("127.0.0.1", 5701);
otherAddress = new Address("127.0.0.1", 5702);
jobPartitionState = new JobPartitionStateImpl(address, WAITING);
jobPartitionStateSameAttributes = new JobPartitionStateImpl(address, WAITING);
jobPartitionStateOtherAddress = new JobPartitionStateImpl(otherAddress, WAITING);
jobPartitionStateOtherState = new JobPartitionStateImpl(address, CANCELLED);
}
Aggregations