Search in sources :

Example 1 with FirewallingServer

use of com.hazelcast.internal.server.FirewallingServer in project hazelcast by hazelcast.

the class SplitBrainTestSupport method createHazelcastInstanceInBrain.

/**
 * Starts a new {@code HazelcastInstance} which is only able to communicate with members on one of the two brains.
 *
 * @param brain index of brain to start a new instance in (0 to start instance in first brain or 1 to start instance in
 *              second brain)
 * @return a HazelcastInstance whose {@code MockJoiner} has blacklisted the other brain's members and its connection
 * manager blocks connections to other brain's members
 * @see TestHazelcastInstanceFactory#newHazelcastInstance(Address, Config, Address[])
 */
protected HazelcastInstance createHazelcastInstanceInBrain(int brain) {
    Address newMemberAddress = factory.nextAddress();
    Brains brains = getBrains();
    HazelcastInstance[] instancesToBlock = brain == 1 ? brains.firstHalf : brains.secondHalf;
    List<Address> addressesToBlock = new ArrayList<>(instancesToBlock.length);
    for (HazelcastInstance hz : instancesToBlock) {
        if (isInstanceActive(hz)) {
            addressesToBlock.add(Accessors.getAddress(hz));
            // block communication from these instances to the new address
            FirewallingServer networkingService = getFireWalledNetworkingService(hz);
            FirewallingServer.FirewallingServerConnectionManager endpointManager = (FirewallingServer.FirewallingServerConnectionManager) networkingService.getConnectionManager(MEMBER);
            endpointManager.blockNewConnection(newMemberAddress);
            endpointManager.closeActiveConnection(newMemberAddress);
        }
    }
    // indicate that we need to unblacklist addresses from the joiner when split-brain will be healed
    unblacklistHint = true;
    // create a new Hazelcast instance which has blocked addresses blacklisted in its joiner
    return factory.newHazelcastInstance(newMemberAddress, config(), addressesToBlock.toArray(new Address[0]));
}
Also used : FirewallingServer(com.hazelcast.internal.server.FirewallingServer) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) ArrayList(java.util.ArrayList)

Example 2 with FirewallingServer

use of com.hazelcast.internal.server.FirewallingServer in project hazelcast by hazelcast.

the class MockNodeContext method createServer.

@Override
public Server createServer(Node node, ServerSocketRegistry serverSocketRegistry, LocalAddressRegistry addressRegistry) {
    TcpServerContext serverContext = new TcpServerContext(node, node.nodeEngine);
    MockServer mockNetworkingService = new MockServer(serverContext, node, registry);
    return new FirewallingServer(mockNetworkingService, initiallyBlockedAddresses);
}
Also used : FirewallingServer(com.hazelcast.internal.server.FirewallingServer) TcpServerContext(com.hazelcast.internal.server.tcp.TcpServerContext)

Example 3 with FirewallingServer

use of com.hazelcast.internal.server.FirewallingServer in project hazelcast by hazelcast.

the class FirewallingConnectionManagerConstructorTest method testConstructor.

@Test
public void testConstructor() throws Exception {
    Server delegate = mock(Server.class);
    Address address = new Address("172.16.16.1", 4223);
    Set<Address> blockedAddresses = Collections.singleton(address);
    FirewallingServer ns = new FirewallingServer(delegate, blockedAddresses);
    FirewallingNetworkingInstanceConstructor constructor = new FirewallingNetworkingInstanceConstructor(FirewallingServer.class);
    FirewallingServer clonedConnectionManager = (FirewallingServer) constructor.createNew(ns);
    assertEquals(delegate, getFieldValueReflectively(clonedConnectionManager, "delegate"));
    assertEquals(blockedAddresses, getFieldValueReflectively(clonedConnectionManager, "blockedAddresses"));
}
Also used : FirewallingServer(com.hazelcast.internal.server.FirewallingServer) Server(com.hazelcast.internal.server.Server) FirewallingServer(com.hazelcast.internal.server.FirewallingServer) Address(com.hazelcast.cluster.Address) FirewallingNetworkingInstanceConstructor(com.hazelcast.test.starter.constructor.FirewallingNetworkingInstanceConstructor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

FirewallingServer (com.hazelcast.internal.server.FirewallingServer)3 Address (com.hazelcast.cluster.Address)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Server (com.hazelcast.internal.server.Server)1 TcpServerContext (com.hazelcast.internal.server.tcp.TcpServerContext)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 FirewallingNetworkingInstanceConstructor (com.hazelcast.test.starter.constructor.FirewallingNetworkingInstanceConstructor)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1