Search in sources :

Example 71 with Address

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

the class DefaultAddressPickerTest method testBindAddress.

private void testBindAddress(InetAddress address) throws Exception {
    addressPicker = new DefaultAddressPicker(config, properties, logger);
    addressPicker.pickAddress();
    int port = config.getNetworkConfig().getPort();
    assertEquals(new Address(address, port), addressPicker.getBindAddress());
    assertEquals(addressPicker.getBindAddress(), addressPicker.getPublicAddress());
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) Inet6Address(java.net.Inet6Address)

Example 72 with Address

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

the class DefaultAddressPickerTest method testPublicAddress_withSpecifiedHostAndPortViaProperty.

@Test
public void testPublicAddress_withSpecifiedHostAndPortViaProperty() throws Exception {
    String host = PUBLIC_HOST;
    int port = 6789;
    config.setProperty("hazelcast.local.publicAddress", host + ":" + port);
    addressPicker = new DefaultAddressPicker(config, properties, logger);
    addressPicker.pickAddress();
    assertEquals(new Address(host, port), addressPicker.getPublicAddress());
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) Inet6Address(java.net.Inet6Address) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 73 with Address

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

the class JoinMessageTrustCheckerTest method createJoinMessage.

private JoinMessage createJoinMessage(String ip) throws UnknownHostException {
    InetAddress inetAddress = InetAddress.getByName(ip);
    Address address = new Address(inetAddress, 5701);
    ConfigCheck configCheck = new ConfigCheck();
    return new JoinMessage(Packet.VERSION, 0, MemberVersion.UNKNOWN, address, "uuid", false, configCheck);
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) InetAddress(java.net.InetAddress)

Example 74 with Address

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

the class MemberImplTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    hazelcastInstance = new HazelcastInstanceImpl("test", new Config(), new DefaultNodeContext());
    address = new Address("127.0.0.1", 5701);
}
Also used : Address(com.hazelcast.nio.Address) Config(com.hazelcast.config.Config) BeforeClass(org.junit.BeforeClass)

Example 75 with Address

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

the class CacheSplitBrainHandler method prepareMergeRunnable.

Runnable prepareMergeRunnable() {
    final Map<String, Map<Data, CacheRecord>> recordMap = new HashMap<String, Map<Data, CacheRecord>>(configs.size());
    final IPartitionService partitionService = nodeEngine.getPartitionService();
    final int partitionCount = partitionService.getPartitionCount();
    final Address thisAddress = nodeEngine.getClusterService().getThisAddress();
    for (int i = 0; i < partitionCount; i++) {
        // Add your owned entries so they will be merged
        if (thisAddress.equals(partitionService.getPartitionOwner(i))) {
            CachePartitionSegment segment = segments[i];
            Iterator<ICacheRecordStore> iter = segment.recordStoreIterator();
            while (iter.hasNext()) {
                ICacheRecordStore cacheRecordStore = iter.next();
                if (!(cacheRecordStore instanceof SplitBrainAwareCacheRecordStore)) {
                    continue;
                }
                String cacheName = cacheRecordStore.getName();
                Map<Data, CacheRecord> records = recordMap.get(cacheName);
                if (records == null) {
                    records = new HashMap<Data, CacheRecord>(cacheRecordStore.size());
                    recordMap.put(cacheName, records);
                }
                for (Map.Entry<Data, CacheRecord> cacheRecordEntry : cacheRecordStore.getReadOnlyRecords().entrySet()) {
                    Data key = cacheRecordEntry.getKey();
                    CacheRecord cacheRecord = cacheRecordEntry.getValue();
                    records.put(key, cacheRecord);
                }
                // Clear all records either owned or backup
                cacheRecordStore.clear();
                // send the cache invalidation event regardless if any actually cleared or not (no need to know how many
                // actually cleared)
                final CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
                cacheService.sendInvalidationEvent(cacheName, null, AbstractCacheRecordStore.SOURCE_NOT_AVAILABLE);
            }
        }
    }
    return new CacheMerger(nodeEngine, configs, recordMap, mergePolicyProvider);
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) IPartitionService(com.hazelcast.spi.partition.IPartitionService) Data(com.hazelcast.nio.serialization.Data) CacheRecord(com.hazelcast.cache.impl.record.CacheRecord) HashMap(java.util.HashMap) Map(java.util.Map)

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