Search in sources :

Example 41 with Address

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);
        }
    });
}
Also used : Address(com.hazelcast.nio.Address) Config(com.hazelcast.config.Config) IOException(java.io.IOException) IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TcpIpConnectionManager(com.hazelcast.nio.tcp.TcpIpConnectionManager) Socket(java.net.Socket) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 42 with Address

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);
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) Address(com.hazelcast.nio.Address)

Example 43 with Address

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);
            }
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node)

Example 44 with Address

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 45 with Address

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);
}
Also used : Address(com.hazelcast.nio.Address) Before(org.junit.Before)

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