Search in sources :

Example 6 with ClientMembershipListener

use of org.apache.geode.management.membership.ClientMembershipListener in project geode by apache.

the class UniversalMembershipListenerAdapterDUnitTest method doTestServerEventsInLonerClient.

private void doTestServerEventsInLonerClient() throws Exception {
    final boolean[] firedAdapter = new boolean[3];
    final DistributedMember[] memberAdapter = new DistributedMember[3];
    final String[] memberIdAdapter = new String[3];
    final boolean[] isClientAdapter = new boolean[3];
    final boolean[] firedBridge = new boolean[3];
    final DistributedMember[] memberBridge = new DistributedMember[3];
    final String[] memberIdBridge = new String[3];
    final boolean[] isClientBridge = new boolean[3];
    final boolean[] firedAdapterDuplicate = new boolean[3];
    final boolean[] firedBridgeDuplicate = new boolean[3];
    UniversalMembershipListenerAdapter adapter = new UniversalMembershipListenerAdapter() {

        @Override
        public synchronized void memberJoined(MembershipEvent event) {
            System.out.println("[testServerEventsInLonerClient] memberJoined >" + event.getMemberId() + "<");
            firedAdapterDuplicate[JOINED] = firedAdapter[JOINED];
            firedAdapter[JOINED] = true;
            memberAdapter[JOINED] = event.getDistributedMember();
            memberIdAdapter[JOINED] = event.getMemberId();
            if (event instanceof UniversalMembershipListenerAdapter.AdaptedMembershipEvent) {
                isClientAdapter[JOINED] = ((UniversalMembershipListenerAdapter.AdaptedMembershipEvent) event).isClient();
            }
            notify();
        }

        @Override
        public synchronized void memberLeft(MembershipEvent event) {
            System.out.println("[testServerEventsInLonerClient] memberLeft >" + event.getMemberId() + "<");
            firedAdapterDuplicate[LEFT] = firedAdapter[LEFT];
            firedAdapter[LEFT] = true;
            memberAdapter[LEFT] = event.getDistributedMember();
            memberIdAdapter[LEFT] = event.getMemberId();
            if (event instanceof UniversalMembershipListenerAdapter.AdaptedMembershipEvent) {
                isClientAdapter[LEFT] = ((UniversalMembershipListenerAdapter.AdaptedMembershipEvent) event).isClient();
            }
            notify();
        }

        @Override
        public synchronized void memberCrashed(MembershipEvent event) {
            System.out.println("[testServerEventsInLonerClient] memberCrashed >" + event.getMemberId() + "<");
            firedAdapterDuplicate[CRASHED] = firedAdapter[CRASHED];
            firedAdapter[CRASHED] = true;
            memberAdapter[CRASHED] = event.getDistributedMember();
            memberIdAdapter[CRASHED] = event.getMemberId();
            if (event instanceof UniversalMembershipListenerAdapter.AdaptedMembershipEvent) {
                isClientAdapter[CRASHED] = ((UniversalMembershipListenerAdapter.AdaptedMembershipEvent) event).isClient();
            }
            notify();
        }
    };
    ClientMembershipListener bridgeListener = new ClientMembershipListener() {

        public synchronized void memberJoined(ClientMembershipEvent event) {
            firedBridgeDuplicate[JOINED] = firedBridge[JOINED];
            firedBridge[JOINED] = true;
            memberBridge[JOINED] = event.getMember();
            memberIdBridge[JOINED] = event.getMemberId();
            isClientBridge[JOINED] = event.isClient();
            notify();
        }

        public synchronized void memberLeft(ClientMembershipEvent event) {
            firedBridgeDuplicate[LEFT] = firedBridge[LEFT];
            firedBridge[LEFT] = true;
            memberBridge[LEFT] = event.getMember();
            memberIdBridge[LEFT] = event.getMemberId();
            isClientBridge[LEFT] = event.isClient();
            notify();
        }

        public synchronized void memberCrashed(ClientMembershipEvent event) {
            firedBridgeDuplicate[CRASHED] = firedBridge[CRASHED];
            firedBridge[CRASHED] = true;
            memberBridge[CRASHED] = event.getMember();
            memberIdBridge[CRASHED] = event.getMemberId();
            isClientBridge[CRASHED] = event.isClient();
            notify();
        }
    };
    final Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final String name = this.getUniqueName();
    final int[] ports = new int[] { AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET) };
    assertTrue(ports[0] != 0);
    System.out.println("[testServerEventsInLonerClient] create loner bridge client");
    Properties config = new Properties();
    config.put(MCAST_PORT, "0");
    config.put(LOCATORS, "");
    // config.put(LOG_LEVEL, "fine");
    config.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "false");
    getSystem(config);
    System.out.println("[testServerEventsInLonerClient] create system bridge client");
    getSystem();
    // register the bridge listener
    ClientMembership.registerClientMembershipListener(bridgeListener);
    // adapter should've self-registered w/ BridgeMembership
    // String clientMemberId = getMemberId();
    // DistributedMember clientMember = getDistributedMember();
    // create BridgeServer in vm0...
    SerializableCallable createBridgeServer = new SerializableCallable("Create BridgeServer") {

        @Override
        public Object call() {
            System.out.println("[testServerEventsInLonerClient] Create BridgeServer");
            getSystem();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            Region region = createRegion(name, factory.create());
            assertNotNull(region);
            assertNotNull(getRootRegion().getSubregion(name));
            try {
                testServerEventsInLonerClient_port = startBridgeServer(ports[0]);
            } catch (IOException e) {
                getLogWriter().error(e);
                fail(e.getMessage());
            }
            return basicGetSystem().getDistributedMember();
        }
    };
    DistributedMember serverMember = (DistributedMember) vm0.invoke(createBridgeServer);
    String serverMemberId = serverMember.getId();
    // gather details for later creation of pool...
    assertEquals(ports[0], (int) vm0.invoke("getServerPort", () -> UniversalMembershipListenerAdapterDUnitTest.getTestServerEventsInLonerClient_port()));
    System.out.println("[testServerEventsInLonerClient] ports[0]=" + ports[0]);
    System.out.println("[testServerEventsInLonerClient] serverMemberId=" + serverMemberId);
    System.out.println("[testServerEventsInLonerClient] serverMember=" + serverMember);
    // create region which connects to bridge server
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    ClientServerTestCase.configureConnectionPool(factory, NetworkUtils.getServerHostName(host), ports, false, -1, -1, null);
    createRegion(name, factory.create());
    assertNotNull(getRootRegion().getSubregion(name));
    Awaitility.await("wait for join").atMost(ASYNC_EVENT_WAIT_MILLIS, TimeUnit.MILLISECONDS).until(() -> {
        synchronized (adapter) {
            return firedAdapter[JOINED];
        }
    });
    Awaitility.await("wait for join").atMost(ASYNC_EVENT_WAIT_MILLIS, TimeUnit.MILLISECONDS).until(() -> {
        synchronized (bridgeListener) {
            return firedBridge[JOINED];
        }
    });
    System.out.println("[testServerEventsInLonerClient] assert client detected server join");
    assertArrayFalse(firedAdapterDuplicate);
    assertArrayFalse(firedBridgeDuplicate);
    assertTrue(firedBridge[JOINED]);
    assertNotNull(memberBridge[JOINED]);
    assertNotNull(memberIdBridge[JOINED]);
    assertFalse(isClientBridge[JOINED]);
    assertFalse(firedBridge[LEFT]);
    assertNull(memberBridge[LEFT]);
    assertNull(memberIdBridge[LEFT]);
    assertFalse(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertTrue(firedAdapter[JOINED]);
    assertNotNull(memberIdAdapter[JOINED]);
    assertFalse(isClientAdapter[JOINED]);
    assertFalse(firedAdapter[LEFT]);
    assertNull(memberAdapter[LEFT]);
    assertNull(memberIdAdapter[LEFT]);
    assertFalse(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    System.out.println("[testServerEventsInLonerClient] wait for client to fully connect");
    final String pl = getRootRegion().getSubregion(name).getAttributes().getPoolName();
    PoolImpl pi = (PoolImpl) PoolManager.find(pl);
    waitForClientToFullyConnect(pi);
    String expected = "java.io.IOException";
    String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
    String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
    String expected2 = "java.net.ConnectException";
    String addExpected2 = "<ExpectedException action=add>" + expected2 + "</ExpectedException>";
    String removeExpected2 = "<ExpectedException action=remove>" + expected2 + "</ExpectedException>";
    // LogWriter bgexecLogger =
    // new LocalLogWriter(LocalLogWriter.ALL_LEVEL, System.out);
    // bgexecLogger.info(addExpected);
    // bgexecLogger.info(addExpected2);
    LogWriter lw = getSystem().getLogWriter();
    lw.info(addExpected);
    lw.info(addExpected2);
    try {
        vm0.invoke(new SerializableRunnable("Disconnect bridge server") {

            public void run() {
                System.out.println("[testServerEventsInLonerClient] disconnect bridge server");
                closeCache();
            }
        });
        Awaitility.await("wait for server to leave").atMost(ASYNC_EVENT_WAIT_MILLIS, TimeUnit.MILLISECONDS).until(() -> {
            synchronized (adapter) {
                return firedAdapter[LEFT] || firedAdapter[CRASHED];
            }
        });
        Awaitility.await("wait for server to leave").atMost(ASYNC_EVENT_WAIT_MILLIS, TimeUnit.MILLISECONDS).until(() -> {
            synchronized (bridgeListener) {
                return firedBridge[LEFT] || firedBridge[CRASHED];
            }
        });
    } finally {
        // bgexecLogger.info(removeExpected);
        // bgexecLogger.info(removeExpected2);
        lw.info(removeExpected);
        lw.info(removeExpected2);
    }
    System.out.println("[testServerEventsInLonerClient] assert client detected server crashed");
    assertArrayFalse(firedAdapterDuplicate);
    assertArrayFalse(firedBridgeDuplicate);
    assertFalse(firedBridge[JOINED]);
    assertNull(memberIdBridge[JOINED]);
    assertNull(memberBridge[JOINED]);
    assertFalse(isClientBridge[JOINED]);
    assertFalse("Please update testServerEventsInLonerClient to handle memberLeft for BridgeServer.", firedBridge[LEFT]);
    assertNull(memberBridge[LEFT]);
    assertNull(memberIdBridge[LEFT]);
    assertFalse(isClientBridge[LEFT]);
    assertTrue(firedBridge[CRASHED]);
    assertNotNull(memberBridge[CRASHED]);
    assertNotNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertFalse(firedAdapter[JOINED]);
    assertNull(memberAdapter[JOINED]);
    assertNull(memberIdAdapter[JOINED]);
    assertFalse(isClientAdapter[JOINED]);
    assertFalse("Please update testServerEventsInLonerClient to handle BridgeServer LEFT", firedAdapter[LEFT]);
    assertNull(memberAdapter[LEFT]);
    assertNull(memberIdAdapter[LEFT]);
    assertFalse(isClientAdapter[LEFT]);
    // CRASHED fired by Bridge listener
    assertTrue(firedAdapter[CRASHED]);
    assertNotNull(memberAdapter[CRASHED]);
    assertNotNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    // reconnect bridge client to test for crashed event
    serverMember = (DistributedMember) vm0.invoke(createBridgeServer);
    serverMemberId = serverMember.getId();
    // gather details for later creation of pool...
    assertEquals(ports[0], (int) vm0.invoke(() -> UniversalMembershipListenerAdapterDUnitTest.getTestServerEventsInLonerClient_port()));
    serverMember = vm0.invoke(() -> UniversalMembershipListenerAdapterDUnitTest.getDistributedMember());
    System.out.println("[testServerEventsInLonerClient] ports[0]=" + ports[0]);
    System.out.println("[testServerEventsInLonerClient] serverMemberId=" + serverMemberId);
    System.out.println("[testServerEventsInLonerClient] serverMember=" + serverMember);
    Awaitility.await("wait for join").atMost(ASYNC_EVENT_WAIT_MILLIS, TimeUnit.MILLISECONDS).until(() -> {
        synchronized (adapter) {
            return firedAdapter[JOINED];
        }
    });
    Awaitility.await("wait for join").atMost(ASYNC_EVENT_WAIT_MILLIS, TimeUnit.MILLISECONDS).until(() -> {
        synchronized (bridgeListener) {
            return firedBridge[JOINED];
        }
    });
    System.out.println("[testServerEventsInLonerClient] assert client detected server re-join");
    assertArrayFalse(firedAdapterDuplicate);
    assertArrayFalse(firedBridgeDuplicate);
    assertTrue(firedBridge[JOINED]);
    assertNotNull(memberBridge[JOINED]);
    assertNotNull(memberIdBridge[JOINED]);
    assertFalse(isClientBridge[JOINED]);
    assertFalse(firedBridge[LEFT]);
    assertNull(memberBridge[LEFT]);
    assertNull(memberIdBridge[LEFT]);
    assertFalse(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertTrue(firedAdapter[JOINED]);
    assertNotNull(memberAdapter[JOINED]);
    assertNotNull(memberIdAdapter[JOINED]);
    assertFalse(isClientAdapter[JOINED]);
    assertFalse(firedAdapter[LEFT]);
    assertNull(memberAdapter[LEFT]);
    assertNull(memberIdAdapter[LEFT]);
    assertFalse(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
}
Also used : ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) MembershipEvent(org.apache.geode.management.membership.MembershipEvent) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) UniversalMembershipListenerAdapter(org.apache.geode.management.membership.UniversalMembershipListenerAdapter) AttributesFactory(org.apache.geode.cache.AttributesFactory) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) LogWriter(org.apache.geode.LogWriter) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region)

Example 7 with ClientMembershipListener

use of org.apache.geode.management.membership.ClientMembershipListener in project geode by apache.

the class UniversalMembershipListenerAdapterDUnitTest method doTestLonerClientEventsInServer.

private void doTestLonerClientEventsInServer() throws Exception {
    final boolean[] firedSystem = new boolean[3];
    final DistributedMember[] memberSystem = new DistributedMember[3];
    final String[] memberIdSystem = new String[3];
    final boolean[] isClientSystem = new boolean[3];
    final boolean[] firedAdapter = new boolean[3];
    final DistributedMember[] memberAdapter = new DistributedMember[3];
    final String[] memberIdAdapter = new String[3];
    final boolean[] isClientAdapter = new boolean[3];
    final boolean[] firedBridge = new boolean[3];
    final DistributedMember[] memberBridge = new DistributedMember[3];
    final String[] memberIdBridge = new String[3];
    final boolean[] isClientBridge = new boolean[3];
    MembershipListener systemListener = new MembershipListener() {

        @Override
        public synchronized void memberJoined(MembershipEvent event) {
            assertFalse(firedSystem[JOINED]);
            assertNull(memberSystem[JOINED]);
            assertNull(memberIdSystem[JOINED]);
            firedSystem[JOINED] = true;
            memberSystem[JOINED] = event.getDistributedMember();
            memberIdSystem[JOINED] = event.getMemberId();
            notify();
        }

        @Override
        public synchronized void memberLeft(MembershipEvent event) {
            assertFalse(firedSystem[LEFT]);
            assertNull(memberSystem[LEFT]);
            assertNull(memberIdSystem[LEFT]);
            firedSystem[LEFT] = true;
            memberSystem[LEFT] = event.getDistributedMember();
            memberIdSystem[LEFT] = event.getMemberId();
            notify();
        }

        @Override
        public synchronized void memberCrashed(MembershipEvent event) {
            assertFalse(firedSystem[CRASHED]);
            assertNull(memberSystem[CRASHED]);
            assertNull(memberIdSystem[CRASHED]);
            firedSystem[CRASHED] = true;
            memberSystem[CRASHED] = event.getDistributedMember();
            memberIdSystem[CRASHED] = event.getMemberId();
            notify();
        }
    };
    UniversalMembershipListenerAdapter adapter = new UniversalMembershipListenerAdapter() {

        @Override
        public synchronized void memberJoined(MembershipEvent event) {
            assertFalse(firedAdapter[JOINED]);
            assertNull(memberAdapter[JOINED]);
            assertNull(memberIdAdapter[JOINED]);
            assertFalse(isClientAdapter[JOINED]);
            firedAdapter[JOINED] = true;
            memberAdapter[JOINED] = event.getDistributedMember();
            memberIdAdapter[JOINED] = event.getMemberId();
            isClientAdapter[JOINED] = ((UniversalMembershipListenerAdapter.AdaptedMembershipEvent) event).isClient();
            notify();
        }

        @Override
        public synchronized void memberLeft(MembershipEvent event) {
            assertFalse(firedAdapter[LEFT]);
            assertNull(memberAdapter[LEFT]);
            assertNull(memberIdAdapter[LEFT]);
            assertFalse(isClientAdapter[LEFT]);
            firedAdapter[LEFT] = true;
            memberAdapter[LEFT] = event.getDistributedMember();
            memberIdAdapter[LEFT] = event.getMemberId();
            isClientAdapter[LEFT] = ((UniversalMembershipListenerAdapter.AdaptedMembershipEvent) event).isClient();
            notify();
        }

        @Override
        public synchronized void memberCrashed(MembershipEvent event) {
            assertFalse(firedAdapter[CRASHED]);
            assertNull(memberAdapter[CRASHED]);
            assertNull(memberIdAdapter[CRASHED]);
            assertFalse(isClientAdapter[CRASHED]);
            firedAdapter[CRASHED] = true;
            memberAdapter[CRASHED] = event.getDistributedMember();
            memberIdAdapter[CRASHED] = event.getMemberId();
            isClientAdapter[CRASHED] = ((UniversalMembershipListenerAdapter.AdaptedMembershipEvent) event).isClient();
            notify();
        }
    };
    ClientMembershipListener bridgeListener = new ClientMembershipListener() {

        @Override
        public synchronized void memberJoined(ClientMembershipEvent event) {
            assertFalse(firedBridge[JOINED]);
            assertNull(memberBridge[JOINED]);
            assertNull(memberIdBridge[JOINED]);
            assertFalse(isClientBridge[JOINED]);
            firedBridge[JOINED] = true;
            memberBridge[JOINED] = event.getMember();
            memberIdBridge[JOINED] = event.getMemberId();
            isClientBridge[JOINED] = event.isClient();
            notify();
        }

        @Override
        public synchronized void memberLeft(ClientMembershipEvent event) {
            assertFalse(firedBridge[LEFT]);
            assertNull(memberBridge[LEFT]);
            assertNull(memberIdBridge[LEFT]);
            assertFalse(isClientBridge[LEFT]);
            firedBridge[LEFT] = true;
            memberBridge[LEFT] = event.getMember();
            memberIdBridge[LEFT] = event.getMemberId();
            isClientBridge[LEFT] = event.isClient();
            notify();
        }

        @Override
        public synchronized void memberCrashed(ClientMembershipEvent event) {
            assertFalse(firedBridge[CRASHED]);
            assertNull(memberBridge[CRASHED]);
            assertNull(memberIdBridge[CRASHED]);
            assertFalse(isClientBridge[CRASHED]);
            firedBridge[CRASHED] = true;
            memberBridge[CRASHED] = event.getMember();
            memberIdBridge[CRASHED] = event.getMemberId();
            isClientBridge[CRASHED] = event.isClient();
            notify();
        }
    };
    final Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final String name = this.getUniqueName();
    final int[] ports = new int[1];
    // create BridgeServer in controller vm...
    System.out.println("[testLonerClientEventsInServer] Create BridgeServer");
    getSystem();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    Region region = createRegion(name, factory.create());
    assertNotNull(region);
    assertNotNull(getRootRegion().getSubregion(name));
    ports[0] = startBridgeServer(0);
    assertTrue(ports[0] != 0);
    final DistributedMember serverMember = getMemberId();
    final String serverMemberId = serverMember.getId();
    final Properties serverProperties = getSystem().getProperties();
    System.out.println("[testLonerClientEventsInServer] ports[0]=" + ports[0]);
    System.out.println("[testLonerClientEventsInServer] serverMemberId=" + serverMemberId);
    System.out.println("[testLonerClientEventsInServer] serverMember=" + serverMember);
    // register the bridge listener
    ClientMembership.registerClientMembershipListener(bridgeListener);
    GemFireCacheImpl cache = GemFireCacheImpl.getExisting();
    assertNotNull(cache);
    ManagementService service = ManagementService.getExistingManagementService(cache);
    // register the system listener
    service.addMembershipListener(systemListener);
    // register the universal adapter. Not required as this test is only for BridgeClient test
    adapter.registerMembershipListener(service);
    SerializableCallable createBridgeClient = new SerializableCallable("Create bridge client") {

        @Override
        public Object call() {
            System.out.println("[testLonerClientEventsInServer] create bridge client");
            Properties config = new Properties();
            config.setProperty(MCAST_PORT, "0");
            config.setProperty(LOCATORS, "");
            config.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "false");
            getSystem(config);
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            ClientServerTestCase.configureConnectionPool(factory, NetworkUtils.getServerHostName(host), ports, false, -1, -1, null);
            createRegion(name, factory.create());
            assertNotNull(getRootRegion().getSubregion(name));
            return getMemberId();
        }
    };
    // create bridge client in vm0...
    DistributedMember clientMember = (DistributedMember) vm0.invoke(createBridgeClient);
    String clientMemberId = clientMember.getId();
    // should trigger both adapter and bridge listener but not system listener
    synchronized (adapter) {
        if (!firedAdapter[JOINED]) {
            adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (bridgeListener) {
        if (!firedBridge[JOINED]) {
            bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    System.out.println("[testLonerClientEventsInServer] assert server detected client join");
    assertTrue(firedBridge[JOINED]);
    assertEquals(clientMember, memberBridge[JOINED]);
    // as of 6.1 the id can change when a bridge is created or a connection pool is created
    // assertIndexDetailsEquals(clientMemberId, memberIdBridge[JOINED]);
    assertTrue(isClientBridge[JOINED]);
    assertFalse(firedBridge[LEFT]);
    assertNull(memberBridge[LEFT]);
    assertNull(memberIdBridge[LEFT]);
    assertFalse(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertFalse(firedSystem[JOINED]);
    assertNull(memberSystem[JOINED]);
    assertNull(memberIdSystem[JOINED]);
    assertFalse(isClientSystem[JOINED]);
    assertFalse(firedSystem[LEFT]);
    assertNull(memberSystem[LEFT]);
    assertNull(memberIdSystem[LEFT]);
    assertFalse(isClientSystem[LEFT]);
    assertFalse(firedSystem[CRASHED]);
    assertNull(memberSystem[CRASHED]);
    assertNull(memberIdSystem[CRASHED]);
    assertFalse(isClientSystem[CRASHED]);
    resetArraysForTesting(firedSystem, memberSystem, memberIdSystem, isClientSystem);
    assertTrue(firedAdapter[JOINED]);
    assertEquals(clientMember, memberAdapter[JOINED]);
    assertFalse(SocketCreator.resolve_dns);
    assertEquals(clientMemberId, memberIdAdapter[JOINED]);
    assertTrue(isClientAdapter[JOINED]);
    assertFalse(firedAdapter[LEFT]);
    assertNull(memberAdapter[LEFT]);
    assertNull(memberIdAdapter[LEFT]);
    assertFalse(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    vm0.invoke(new SerializableRunnable("Wait for client to fully connect") {

        public void run() {
            System.out.println("[testLonerClientEventsInServer] wait for client to fully connect");
            final String pl = getRootRegion().getSubregion(name).getAttributes().getPoolName();
            PoolImpl pi = (PoolImpl) PoolManager.find(pl);
            waitForClientToFullyConnect(pi);
        }
    });
    vm0.invoke(new SerializableRunnable("Close bridge client region") {

        public void run() {
            System.out.println("[testLonerClientEventsInServer] close bridge client region");
            getRootRegion().getSubregion(name).close();
            PoolManager.close();
        }
    });
    synchronized (adapter) {
        if (!firedAdapter[LEFT]) {
            adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (bridgeListener) {
        if (!firedBridge[LEFT]) {
            bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    System.out.println("[testLonerClientEventsInServer] assert server detected client left");
    assertFalse(firedBridge[JOINED]);
    assertNull(memberIdBridge[JOINED]);
    assertNull(memberBridge[JOINED]);
    assertFalse(isClientBridge[JOINED]);
    assertTrue(firedBridge[LEFT]);
    assertEquals(clientMember, memberBridge[LEFT]);
    assertEquals(clientMemberId, memberIdBridge[LEFT]);
    assertTrue(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertFalse(firedSystem[JOINED]);
    assertNull(memberSystem[JOINED]);
    assertNull(memberIdSystem[JOINED]);
    assertFalse(isClientSystem[JOINED]);
    assertFalse(firedSystem[LEFT]);
    assertNull(memberSystem[LEFT]);
    assertNull(memberIdSystem[LEFT]);
    assertFalse(isClientSystem[LEFT]);
    assertFalse(firedSystem[CRASHED]);
    assertNull(memberSystem[CRASHED]);
    assertNull(memberIdSystem[CRASHED]);
    assertFalse(isClientSystem[CRASHED]);
    resetArraysForTesting(firedSystem, memberSystem, memberIdSystem, isClientSystem);
    assertFalse(firedAdapter[JOINED]);
    assertNull(memberAdapter[JOINED]);
    assertNull(memberIdAdapter[JOINED]);
    assertFalse(isClientAdapter[JOINED]);
    assertTrue(firedAdapter[LEFT]);
    assertEquals(clientMember, memberAdapter[LEFT]);
    assertEquals(clientMemberId, memberIdAdapter[LEFT]);
    assertTrue(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    // reconnect bridge client to test for crashed event
    clientMember = (DistributedMember) vm0.invoke(createBridgeClient);
    clientMemberId = clientMember.getId();
    synchronized (adapter) {
        if (!firedAdapter[JOINED]) {
            adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (bridgeListener) {
        if (!firedBridge[JOINED]) {
            bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    System.out.println("[testLonerClientEventsInServer] assert server detected client re-join");
    assertTrue(firedBridge[JOINED]);
    assertEquals(clientMember, memberBridge[JOINED]);
    assertEquals(clientMemberId, memberIdBridge[JOINED]);
    assertTrue(isClientBridge[JOINED]);
    assertFalse(firedBridge[LEFT]);
    assertNull(memberBridge[LEFT]);
    assertNull(memberIdBridge[LEFT]);
    assertFalse(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertFalse(firedSystem[JOINED]);
    assertNull(memberSystem[JOINED]);
    assertNull(memberIdSystem[JOINED]);
    assertFalse(isClientSystem[JOINED]);
    assertFalse(firedSystem[LEFT]);
    assertNull(memberSystem[LEFT]);
    assertNull(memberIdSystem[LEFT]);
    assertFalse(isClientSystem[LEFT]);
    assertFalse(firedSystem[CRASHED]);
    assertNull(memberSystem[CRASHED]);
    assertNull(memberIdSystem[CRASHED]);
    assertFalse(isClientSystem[CRASHED]);
    resetArraysForTesting(firedSystem, memberSystem, memberIdSystem, isClientSystem);
    assertTrue(firedAdapter[JOINED]);
    assertEquals(clientMember, memberAdapter[JOINED]);
    assertEquals(clientMemberId, memberIdAdapter[JOINED]);
    assertTrue(isClientAdapter[JOINED]);
    assertFalse(firedAdapter[LEFT]);
    assertNull(memberAdapter[LEFT]);
    assertNull(memberIdAdapter[LEFT]);
    assertFalse(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    vm0.invoke(new SerializableRunnable("Wait for client to fully connect") {

        public void run() {
            System.out.println("[testLonerClientEventsInServer] wait for client to fully connect");
            final String pl = getRootRegion().getSubregion(name).getAttributes().getPoolName();
            PoolImpl pi = (PoolImpl) PoolManager.find(pl);
            waitForClientToFullyConnect(pi);
        }
    });
    ServerConnection.setForceClientCrashEvent(true);
    try {
        vm0.invoke(new SerializableRunnable("Stop bridge client") {

            public void run() {
                System.out.println("[testLonerClientEventsInServer] Stop bridge client");
                getRootRegion().getSubregion(name).close();
                PoolManager.close();
            }
        });
        synchronized (adapter) {
            if (!firedAdapter[CRASHED]) {
                adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
            }
        }
        synchronized (bridgeListener) {
            if (!firedBridge[CRASHED]) {
                bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
            }
        }
        System.out.println("[testLonerClientEventsInServer] assert server detected client crashed");
        assertFalse(firedBridge[JOINED]);
        assertNull(memberIdBridge[JOINED]);
        assertNull(memberBridge[JOINED]);
        assertFalse(isClientBridge[JOINED]);
        assertFalse(firedBridge[LEFT]);
        assertNull(memberIdBridge[LEFT]);
        assertNull(memberBridge[LEFT]);
        assertFalse(isClientBridge[LEFT]);
        assertTrue(firedBridge[CRASHED]);
        assertEquals(clientMember, memberBridge[CRASHED]);
        assertEquals(clientMemberId, memberIdBridge[CRASHED]);
        assertTrue(isClientBridge[CRASHED]);
        // resetArraysForTesting(firedBridge, memberIdBridge, isClientBridge);
        assertFalse(firedSystem[JOINED]);
        assertNull(memberSystem[JOINED]);
        assertNull(memberIdSystem[JOINED]);
        assertFalse(isClientSystem[JOINED]);
        assertFalse(firedSystem[LEFT]);
        assertNull(memberSystem[LEFT]);
        assertNull(memberIdSystem[LEFT]);
        assertFalse(isClientSystem[LEFT]);
        assertFalse(firedSystem[CRASHED]);
        assertNull(memberSystem[CRASHED]);
        assertNull(memberIdSystem[CRASHED]);
        assertFalse(isClientSystem[CRASHED]);
        // resetArraysForTesting(firedSystem, memberIdSystem, isClientSystem);
        assertFalse(firedAdapter[JOINED]);
        assertNull(memberAdapter[JOINED]);
        assertNull(memberIdAdapter[JOINED]);
        assertFalse(isClientAdapter[JOINED]);
        assertFalse(firedAdapter[LEFT]);
        assertNull(memberAdapter[LEFT]);
        assertNull(memberIdAdapter[LEFT]);
        assertFalse(isClientAdapter[LEFT]);
        assertTrue(firedAdapter[CRASHED]);
        assertEquals(clientMember, memberAdapter[CRASHED]);
        assertEquals(clientMemberId, memberIdAdapter[CRASHED]);
        assertTrue(isClientAdapter[CRASHED]);
    // resetArraysForTesting(firedAdapter, memberIdAdapter, isClientAdapter);
    } finally {
        ServerConnection.setForceClientCrashEvent(false);
    }
}
Also used : ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) MembershipEvent(org.apache.geode.management.membership.MembershipEvent) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) Host(org.apache.geode.test.dunit.Host) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) UniversalMembershipListenerAdapter(org.apache.geode.management.membership.UniversalMembershipListenerAdapter) AttributesFactory(org.apache.geode.cache.AttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) MembershipListener(org.apache.geode.management.membership.MembershipListener)

Example 8 with ClientMembershipListener

use of org.apache.geode.management.membership.ClientMembershipListener in project geode by apache.

the class UniversalMembershipListenerAdapterDUnitTest method doTestSystemClientEventsInServer.

private void doTestSystemClientEventsInServer() throws Exception {
    final boolean[] firedSystem = new boolean[3];
    final DistributedMember[] memberSystem = new DistributedMember[3];
    final String[] memberIdSystem = new String[3];
    final boolean[] isClientSystem = new boolean[3];
    final boolean[] firedAdapter = new boolean[3];
    final DistributedMember[] memberAdapter = new DistributedMember[3];
    final String[] memberIdAdapter = new String[3];
    final boolean[] isClientAdapter = new boolean[3];
    final boolean[] firedBridge = new boolean[3];
    final DistributedMember[] memberBridge = new DistributedMember[3];
    final String[] memberIdBridge = new String[3];
    final boolean[] isClientBridge = new boolean[3];
    final boolean[] firedSystemDuplicate = new boolean[3];
    final boolean[] firedAdapterDuplicate = new boolean[3];
    final boolean[] firedBridgeDuplicate = new boolean[3];
    MembershipListener systemListener = new MembershipListener() {

        public synchronized void memberJoined(MembershipEvent event) {
            firedSystemDuplicate[JOINED] = firedSystem[JOINED];
            firedSystem[JOINED] = true;
            memberSystem[JOINED] = event.getDistributedMember();
            memberIdSystem[JOINED] = event.getMemberId();
            notify();
        }

        public synchronized void memberLeft(MembershipEvent event) {
            firedSystemDuplicate[LEFT] = firedSystem[LEFT];
            firedSystem[LEFT] = true;
            memberSystem[LEFT] = event.getDistributedMember();
            memberIdSystem[LEFT] = event.getMemberId();
            notify();
        }

        public synchronized void memberCrashed(MembershipEvent event) {
            firedSystemDuplicate[CRASHED] = firedSystem[CRASHED];
            firedSystem[CRASHED] = true;
            memberSystem[CRASHED] = event.getDistributedMember();
            memberIdSystem[CRASHED] = event.getMemberId();
            notify();
        }
    };
    UniversalMembershipListenerAdapter adapter = new UniversalMembershipListenerAdapter() {

        @Override
        public synchronized void memberJoined(MembershipEvent event) {
            getLogWriter().info("[doTestSystemClientEventsInServer] memberJoined >" + event.getMemberId() + "<");
            firedAdapterDuplicate[JOINED] = firedAdapter[JOINED];
            firedAdapter[JOINED] = true;
            memberAdapter[JOINED] = event.getDistributedMember();
            memberIdAdapter[JOINED] = event.getMemberId();
            if (event instanceof UniversalMembershipListenerAdapter.AdaptedMembershipEvent) {
                isClientAdapter[JOINED] = ((UniversalMembershipListenerAdapter.AdaptedMembershipEvent) event).isClient();
            }
            notify();
        }

        @Override
        public synchronized void memberLeft(MembershipEvent event) {
            getLogWriter().info("[doTestSystemClientEventsInServer] memberLeft >" + event.getMemberId() + "<");
            firedAdapterDuplicate[LEFT] = firedAdapter[LEFT];
            firedAdapter[LEFT] = true;
            memberAdapter[LEFT] = event.getDistributedMember();
            memberIdAdapter[LEFT] = event.getMemberId();
            if (event instanceof UniversalMembershipListenerAdapter.AdaptedMembershipEvent) {
                isClientAdapter[LEFT] = ((UniversalMembershipListenerAdapter.AdaptedMembershipEvent) event).isClient();
            }
            notify();
        }

        @Override
        public synchronized void memberCrashed(MembershipEvent event) {
            getLogWriter().info("[doTestSystemClientEventsInServer] memberCrashed >" + event.getMemberId() + "<");
            firedAdapterDuplicate[CRASHED] = firedAdapter[CRASHED];
            firedAdapter[CRASHED] = true;
            memberAdapter[CRASHED] = event.getDistributedMember();
            memberIdAdapter[CRASHED] = event.getMemberId();
            if (event instanceof UniversalMembershipListenerAdapter.AdaptedMembershipEvent) {
                isClientAdapter[CRASHED] = ((UniversalMembershipListenerAdapter.AdaptedMembershipEvent) event).isClient();
            }
            notify();
        }
    };
    ClientMembershipListener bridgeListener = new ClientMembershipListener() {

        public synchronized void memberJoined(ClientMembershipEvent event) {
            firedBridgeDuplicate[JOINED] = firedBridge[JOINED];
            firedBridge[JOINED] = true;
            memberBridge[JOINED] = event.getMember();
            memberIdBridge[JOINED] = event.getMemberId();
            isClientBridge[JOINED] = event.isClient();
            notify();
        }

        public synchronized void memberLeft(ClientMembershipEvent event) {
            firedBridgeDuplicate[LEFT] = firedBridge[LEFT];
            firedBridge[LEFT] = true;
            memberBridge[LEFT] = event.getMember();
            memberIdBridge[LEFT] = event.getMemberId();
            isClientBridge[LEFT] = event.isClient();
            notify();
        }

        public synchronized void memberCrashed(ClientMembershipEvent event) {
            firedBridgeDuplicate[CRASHED] = firedBridge[CRASHED];
            firedBridge[CRASHED] = true;
            memberBridge[CRASHED] = event.getMember();
            memberIdBridge[CRASHED] = event.getMemberId();
            isClientBridge[CRASHED] = event.isClient();
            notify();
        }
    };
    final Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final String name = this.getUniqueName();
    final int[] ports = new int[1];
    // create BridgeServer in controller vm...
    System.out.println("[doTestSystemClientEventsInServer] Create BridgeServer");
    getSystem();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    Region region = createRegion(name, factory.create());
    assertNotNull(region);
    assertNotNull(getRootRegion().getSubregion(name));
    ports[0] = startBridgeServer(0);
    assertTrue(ports[0] != 0);
    final DistributedMember serverMember = getMemberId();
    final String serverMemberId = serverMember.getId();
    final Properties serverProperties = getSystem().getProperties();
    // Below removed properties are already got copied as cluster SSL properties
    serverProperties.remove(CLUSTER_SSL_ENABLED);
    serverProperties.remove(CLUSTER_SSL_CIPHERS);
    serverProperties.remove(CLUSTER_SSL_PROTOCOLS);
    serverProperties.remove(CLUSTER_SSL_REQUIRE_AUTHENTICATION);
    System.out.println("[doTestSystemClientEventsInServer] ports[0]=" + ports[0]);
    System.out.println("[doTestSystemClientEventsInServer] serverMemberId=" + serverMemberId);
    System.out.println("[doTestSystemClientEventsInServer] serverMember=" + serverMember);
    // register the bridge listener
    ClientMembership.registerClientMembershipListener(bridgeListener);
    GemFireCacheImpl cache = GemFireCacheImpl.getExisting();
    assertNotNull(cache);
    ManagementService service = ManagementService.getExistingManagementService(cache);
    // register the system listener
    service.addMembershipListener(systemListener);
    // register the universal adapter.
    adapter.registerMembershipListener(service);
    SerializableCallable createBridgeClient = new SerializableCallable("Create bridge client") {

        @Override
        public Object call() {
            System.out.println("[doTestSystemClientEventsInServer] create system bridge client");
            assertTrue(getSystem(serverProperties).isConnected());
            assertFalse(getCache().isClosed());
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            ClientServerTestCase.configureConnectionPool(factory, NetworkUtils.getServerHostName(host), ports, false, -1, -1, null);
            createRegion(name, factory.create());
            assertNotNull(getRootRegion().getSubregion(name));
            return getMemberId();
        }
    };
    // create bridge client in vm0...
    DistributedMember clientMember = (DistributedMember) vm0.invoke(createBridgeClient);
    String clientMemberId = clientMember.getId();
    // should trigger both adapter and bridge listener but not system listener
    synchronized (adapter) {
        if (!firedAdapter[JOINED]) {
            adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (bridgeListener) {
        if (!firedBridge[JOINED]) {
            bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (systemListener) {
        if (!firedSystem[JOINED]) {
            systemListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    System.out.println("[doTestSystemClientEventsInServer] assert server detected client join");
    assertArrayFalse(firedSystemDuplicate);
    assertArrayFalse(firedAdapterDuplicate);
    assertArrayFalse(firedBridgeDuplicate);
    assertTrue(firedBridge[JOINED]);
    assertEquals(clientMember, memberBridge[JOINED]);
    assertEquals(clientMemberId, memberIdBridge[JOINED]);
    assertTrue(isClientBridge[JOINED]);
    assertFalse(firedBridge[LEFT]);
    assertNull(memberBridge[LEFT]);
    assertNull(memberIdBridge[LEFT]);
    assertFalse(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertTrue(firedSystem[JOINED]);
    assertEquals(clientMember, memberSystem[JOINED]);
    assertEquals(clientMemberId, memberIdSystem[JOINED]);
    assertFalse(isClientSystem[JOINED]);
    assertFalse(firedSystem[LEFT]);
    assertNull(memberSystem[LEFT]);
    assertNull(memberIdSystem[LEFT]);
    assertFalse(isClientSystem[LEFT]);
    assertFalse(firedSystem[CRASHED]);
    assertNull(memberSystem[CRASHED]);
    assertNull(memberIdSystem[CRASHED]);
    assertFalse(isClientSystem[CRASHED]);
    resetArraysForTesting(firedSystem, memberSystem, memberIdSystem, isClientSystem);
    assertTrue(firedAdapter[JOINED]);
    assertEquals(clientMember, memberAdapter[JOINED]);
    assertEquals(clientMemberId, memberIdAdapter[JOINED]);
    // assertTrue(isClientAdapter[JOINED]);
    assertFalse(firedAdapter[LEFT]);
    assertNull(memberAdapter[LEFT]);
    assertNull(memberIdAdapter[LEFT]);
    assertFalse(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    vm0.invoke(new SerializableRunnable("Wait for client to fully connect") {

        public void run() {
            System.out.println("[doTestSystemClientEventsInServer] wait for client to fully connect");
            final String pl = getRootRegion().getSubregion(name).getAttributes().getPoolName();
            PoolImpl pi = (PoolImpl) PoolManager.find(pl);
            waitForClientToFullyConnect(pi);
        }
    });
    // close bridge client region
    vm0.invoke(new SerializableRunnable("Close bridge client region") {

        public void run() {
            System.out.println("[doTestSystemClientEventsInServer] close bridge client region");
            getRootRegion().getSubregion(name).close();
            PoolManager.close();
        }
    });
    synchronized (adapter) {
        if (!firedAdapter[LEFT]) {
            adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (bridgeListener) {
        if (!firedBridge[LEFT]) {
            bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    System.out.println("[doTestSystemClientEventsInServer] assert server detected client left");
    assertArrayFalse(firedSystemDuplicate);
    assertArrayFalse(firedAdapterDuplicate);
    assertArrayFalse(firedBridgeDuplicate);
    assertFalse(firedBridge[JOINED]);
    assertNull(memberIdBridge[JOINED]);
    assertNull(memberBridge[JOINED]);
    assertFalse(isClientBridge[JOINED]);
    assertTrue(firedBridge[LEFT]);
    assertEquals(clientMember, memberBridge[LEFT]);
    assertEquals(clientMemberId, memberIdBridge[LEFT]);
    assertTrue(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertFalse(firedSystem[JOINED]);
    assertNull(memberSystem[JOINED]);
    assertNull(memberIdSystem[JOINED]);
    assertFalse(isClientSystem[JOINED]);
    assertFalse(firedSystem[LEFT]);
    assertNull(memberSystem[LEFT]);
    assertNull(memberIdSystem[LEFT]);
    assertFalse(isClientSystem[LEFT]);
    assertFalse(firedSystem[CRASHED]);
    assertNull(memberSystem[CRASHED]);
    assertNull(memberIdSystem[CRASHED]);
    assertFalse(isClientSystem[CRASHED]);
    resetArraysForTesting(firedSystem, memberSystem, memberIdSystem, isClientSystem);
    assertFalse(firedAdapter[JOINED]);
    assertNull(memberAdapter[JOINED]);
    assertNull(memberIdAdapter[JOINED]);
    assertFalse(isClientAdapter[JOINED]);
    assertTrue(firedAdapter[LEFT]);
    assertEquals(clientMember, memberAdapter[LEFT]);
    assertEquals(clientMemberId, memberIdAdapter[LEFT]);
    assertTrue(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    // reconnect bridge client
    clientMember = (DistributedMember) vm0.invoke(createBridgeClient);
    clientMemberId = clientMember.getId();
    synchronized (adapter) {
        if (!firedAdapter[JOINED]) {
            adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (bridgeListener) {
        if (!firedBridge[JOINED]) {
            bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    System.out.println("[doTestSystemClientEventsInServer] assert server detected client re-join");
    assertArrayFalse(firedSystemDuplicate);
    assertArrayFalse(firedAdapterDuplicate);
    assertArrayFalse(firedBridgeDuplicate);
    assertTrue(firedBridge[JOINED]);
    assertEquals(clientMember, memberBridge[JOINED]);
    assertEquals(clientMemberId, memberIdBridge[JOINED]);
    assertTrue(isClientBridge[JOINED]);
    assertFalse(firedBridge[LEFT]);
    assertNull(memberBridge[LEFT]);
    assertNull(memberIdBridge[LEFT]);
    assertFalse(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertFalse(firedSystem[JOINED]);
    assertNull(memberSystem[JOINED]);
    assertNull(memberIdSystem[JOINED]);
    assertFalse(isClientSystem[JOINED]);
    assertFalse(firedSystem[LEFT]);
    assertNull(memberSystem[LEFT]);
    assertNull(memberIdSystem[LEFT]);
    assertFalse(isClientSystem[LEFT]);
    assertFalse(firedSystem[CRASHED]);
    assertNull(memberSystem[CRASHED]);
    assertNull(memberIdSystem[CRASHED]);
    assertFalse(isClientSystem[CRASHED]);
    resetArraysForTesting(firedSystem, memberSystem, memberIdSystem, isClientSystem);
    assertTrue(firedAdapter[JOINED]);
    assertEquals(clientMember, memberAdapter[JOINED]);
    assertEquals(clientMemberId, memberIdAdapter[JOINED]);
    // assertTrue(isClientAdapter[JOINED]);
    assertFalse(firedAdapter[LEFT]);
    assertNull(memberAdapter[LEFT]);
    assertNull(memberIdAdapter[LEFT]);
    assertFalse(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    vm0.invoke(new SerializableRunnable("Wait for client to fully connect") {

        public void run() {
            System.out.println("[doTestSystemClientEventsInServer] wait for client to fully connect");
            final String pl = getRootRegion().getSubregion(name).getAttributes().getPoolName();
            PoolImpl pi = (PoolImpl) PoolManager.find(pl);
            waitForClientToFullyConnect(pi);
        }
    });
    // have bridge client disconnect from system
    vm0.invoke(new SerializableRunnable("Disconnect bridge client") {

        public void run() {
            System.out.println("[doTestSystemClientEventsInServer] disconnect bridge client");
            closeCache();
            disconnectFromDS();
        }
    });
    synchronized (adapter) {
        if (!firedAdapter[LEFT]) {
            adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (systemListener) {
        if (!firedSystem[LEFT]) {
            systemListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (bridgeListener) {
        if (!firedBridge[LEFT]) {
            bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    System.out.println("[doTestSystemClientEventsInServer] assert server detected client left");
    assertArrayFalse(firedSystemDuplicate);
    assertArrayFalse(firedAdapterDuplicate);
    assertArrayFalse(firedBridgeDuplicate);
    assertFalse(firedBridge[JOINED]);
    assertNull(memberBridge[JOINED]);
    assertNull(memberIdBridge[JOINED]);
    assertFalse(isClientBridge[JOINED]);
    assertTrue(firedBridge[LEFT]);
    assertEquals(clientMember, memberBridge[LEFT]);
    assertEquals(clientMemberId, memberIdBridge[LEFT]);
    assertTrue(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertFalse(firedSystem[JOINED]);
    assertNull(memberSystem[JOINED]);
    assertNull(memberIdSystem[JOINED]);
    assertFalse(isClientSystem[JOINED]);
    assertTrue(firedSystem[LEFT]);
    assertEquals(clientMember, memberSystem[LEFT]);
    assertEquals(clientMemberId, memberIdSystem[LEFT]);
    assertFalse(isClientSystem[LEFT]);
    assertFalse(firedSystem[CRASHED]);
    assertNull(memberSystem[CRASHED]);
    assertNull(memberIdSystem[CRASHED]);
    assertFalse(isClientSystem[CRASHED]);
    resetArraysForTesting(firedSystem, memberSystem, memberIdSystem, isClientSystem);
    assertFalse(firedAdapter[JOINED]);
    assertNull(memberAdapter[JOINED]);
    assertNull(memberIdAdapter[JOINED]);
    assertFalse(isClientAdapter[JOINED]);
    assertTrue(firedAdapter[LEFT]);
    assertEquals(clientMember, memberAdapter[LEFT]);
    assertEquals(clientMemberId, memberIdAdapter[LEFT]);
    // assertTrue(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    // reconnect bridge client
    clientMember = (DistributedMember) vm0.invoke(createBridgeClient);
    clientMemberId = clientMember.getId();
    synchronized (adapter) {
        if (!firedAdapter[JOINED]) {
            adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (systemListener) {
        if (!firedSystem[JOINED]) {
            systemListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (bridgeListener) {
        if (!firedBridge[JOINED]) {
            bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    System.out.println("[doTestSystemClientEventsInServer] assert server detected client re-join");
    assertArrayFalse(firedSystemDuplicate);
    assertArrayFalse(firedAdapterDuplicate);
    assertArrayFalse(firedBridgeDuplicate);
    assertTrue(firedBridge[JOINED]);
    assertEquals(clientMember, memberBridge[JOINED]);
    assertEquals(clientMemberId, memberIdBridge[JOINED]);
    assertTrue(isClientBridge[JOINED]);
    assertFalse(firedBridge[LEFT]);
    assertNull(memberBridge[LEFT]);
    assertNull(memberIdBridge[LEFT]);
    assertFalse(isClientBridge[LEFT]);
    assertFalse(firedBridge[CRASHED]);
    assertNull(memberBridge[CRASHED]);
    assertNull(memberIdBridge[CRASHED]);
    assertFalse(isClientBridge[CRASHED]);
    resetArraysForTesting(firedBridge, memberBridge, memberIdBridge, isClientBridge);
    assertTrue(firedSystem[JOINED]);
    assertEquals(clientMember, memberSystem[JOINED]);
    assertEquals(clientMemberId, memberIdSystem[JOINED]);
    assertFalse(isClientSystem[JOINED]);
    assertFalse(firedSystem[LEFT]);
    assertNull(memberSystem[LEFT]);
    assertNull(memberIdSystem[LEFT]);
    assertFalse(isClientSystem[LEFT]);
    assertFalse(firedSystem[CRASHED]);
    assertNull(memberSystem[CRASHED]);
    assertNull(memberIdSystem[CRASHED]);
    assertFalse(isClientSystem[CRASHED]);
    resetArraysForTesting(firedSystem, memberSystem, memberIdSystem, isClientSystem);
    assertTrue(firedAdapter[JOINED]);
    assertEquals(clientMember, memberAdapter[JOINED]);
    assertEquals(clientMemberId, memberIdAdapter[JOINED]);
    // assertTrue(isClientAdapter[JOINED]);
    assertFalse(firedAdapter[LEFT]);
    assertNull(memberAdapter[LEFT]);
    assertNull(memberIdAdapter[LEFT]);
    assertFalse(isClientAdapter[LEFT]);
    assertFalse(firedAdapter[CRASHED]);
    assertNull(memberAdapter[CRASHED]);
    assertNull(memberIdAdapter[CRASHED]);
    assertFalse(isClientAdapter[CRASHED]);
    resetArraysForTesting(firedAdapter, memberAdapter, memberIdAdapter, isClientAdapter);
    vm0.invoke(new SerializableRunnable("Wait for client to fully connect") {

        public void run() {
            System.out.println("[doTestSystemClientEventsInServer] wait for client to fully connect");
            final String pl = getRootRegion().getSubregion(name).getAttributes().getPoolName();
            PoolImpl pi = (PoolImpl) PoolManager.find(pl);
            waitForClientToFullyConnect(pi);
        }
    });
    // close bridge client region with test hook for crash
    ServerConnection.setForceClientCrashEvent(true);
    try {
        vm0.invoke(new SerializableRunnable("Close bridge client region") {

            public void run() {
                System.out.println("[doTestSystemClientEventsInServer] close bridge client region");
                getRootRegion().getSubregion(name).close();
                PoolManager.close();
            }
        });
        synchronized (adapter) {
            if (!firedAdapter[CRASHED]) {
                adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
            }
        }
        synchronized (bridgeListener) {
            if (!firedBridge[CRASHED]) {
                bridgeListener.wait(ASYNC_EVENT_WAIT_MILLIS);
            }
        }
        getLogWriter().info("[doTestSystemClientEventsInServer] assert server detected client crashed");
        assertArrayFalse(firedSystemDuplicate);
        assertArrayFalse(firedAdapterDuplicate);
        assertArrayFalse(firedBridgeDuplicate);
        assertFalse(firedBridge[JOINED]);
        assertNull(memberBridge[JOINED]);
        assertNull(memberIdBridge[JOINED]);
        assertFalse(isClientBridge[JOINED]);
        assertFalse(firedBridge[LEFT]);
        assertNull(memberBridge[LEFT]);
        assertNull(memberIdBridge[LEFT]);
        assertFalse(isClientBridge[LEFT]);
        assertTrue(firedBridge[CRASHED]);
        assertEquals(clientMember, memberBridge[CRASHED]);
        assertEquals(clientMemberId, memberIdBridge[CRASHED]);
        assertTrue(isClientBridge[CRASHED]);
        assertFalse(firedSystem[JOINED]);
        assertNull(memberSystem[JOINED]);
        assertNull(memberIdSystem[JOINED]);
        assertFalse(isClientSystem[JOINED]);
        assertFalse(firedSystem[LEFT]);
        assertNull(memberSystem[LEFT]);
        assertNull(memberIdSystem[LEFT]);
        assertFalse(isClientSystem[LEFT]);
        assertFalse(firedSystem[CRASHED]);
        assertNull(memberSystem[CRASHED]);
        assertNull(memberIdSystem[CRASHED]);
        assertFalse(isClientSystem[CRASHED]);
        assertFalse(firedAdapter[JOINED]);
        assertNull(memberAdapter[JOINED]);
        assertNull(memberIdAdapter[JOINED]);
        assertFalse(isClientAdapter[JOINED]);
        assertFalse(firedAdapter[LEFT]);
        assertNull(memberAdapter[LEFT]);
        assertNull(memberIdAdapter[LEFT]);
        assertFalse(isClientAdapter[LEFT]);
        assertTrue(firedAdapter[CRASHED]);
        assertEquals(clientMember, memberAdapter[CRASHED]);
        assertEquals(clientMemberId, memberIdAdapter[CRASHED]);
        assertTrue(isClientAdapter[CRASHED]);
    } finally {
        ServerConnection.setForceClientCrashEvent(false);
    }
}
Also used : ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) MembershipEvent(org.apache.geode.management.membership.MembershipEvent) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) Host(org.apache.geode.test.dunit.Host) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) UniversalMembershipListenerAdapter(org.apache.geode.management.membership.UniversalMembershipListenerAdapter) AttributesFactory(org.apache.geode.cache.AttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) MembershipListener(org.apache.geode.management.membership.MembershipListener)

Example 9 with ClientMembershipListener

use of org.apache.geode.management.membership.ClientMembershipListener in project geode by apache.

the class ManagementAdapter method handleCacheServerStart.

/**
   * Assumption is its a cache server instance. For Gateway receiver there will be a separate method
   * 
   * @param cacheServer cache server instance
   */
public void handleCacheServerStart(CacheServer cacheServer) {
    if (!isServiceInitialised("handleCacheServerStart")) {
        return;
    }
    CacheServerBridge cacheServerBridge = new CacheServerBridge(cacheServer, internalCache);
    cacheServerBridge.setMemberMBeanBridge(memberMBeanBridge);
    CacheServerMBean cacheServerMBean = new CacheServerMBean(cacheServerBridge);
    ObjectName cacheServerMBeanName = MBeanJMXAdapter.getClientServiceMBeanName(cacheServer.getPort(), internalCache.getDistributedSystem().getDistributedMember());
    ObjectName changedMBeanName = service.registerInternalMBean((CacheServerMXBean) cacheServerMBean, cacheServerMBeanName);
    ClientMembershipListener managementClientListener = new CacheServerMembershipListenerAdapter(cacheServerMBean, memberLevelNotifEmitter, changedMBeanName);
    ClientMembership.registerClientMembershipListener(managementClientListener);
    cacheServerBridge.setClientMembershipListener(managementClientListener);
    service.federate(changedMBeanName, CacheServerMXBean.class, true);
    Notification notification = new Notification(JMXNotificationType.CACHE_SERVER_STARTED, memberSource, SequenceNumber.next(), System.currentTimeMillis(), ManagementConstants.CACHE_SERVER_STARTED_PREFIX);
    memberLevelNotifEmitter.sendNotification(notification);
    memberMBeanBridge.setCacheServer(true);
}
Also used : ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName)

Example 10 with ClientMembershipListener

use of org.apache.geode.management.membership.ClientMembershipListener in project geode by apache.

the class AutoConnectionSourceImplJUnitTest method testServerLocationUsedInListenerNotification.

@Test
public void testServerLocationUsedInListenerNotification() throws Exception {
    final ClientMembershipEvent[] listenerEvents = new ClientMembershipEvent[1];
    ClientMembershipListener listener = new ClientMembershipListener() {

        @Override
        public void memberJoined(final ClientMembershipEvent event) {
            synchronized (listenerEvents) {
                listenerEvents[0] = event;
            }
        }

        @Override
        public void memberLeft(final ClientMembershipEvent event) {
        }

        @Override
        public void memberCrashed(final ClientMembershipEvent event) {
        }
    };
    InternalClientMembership.registerClientMembershipListener(listener);
    ServerLocation location = new ServerLocation("1.1.1.1", 0);
    InternalClientMembership.notifyServerJoined(location);
    Awaitility.await("wait for listener notification").atMost(10, TimeUnit.SECONDS).until(() -> {
        synchronized (listenerEvents) {
            return listenerEvents[0] != null;
        }
    });
    assertEquals("1.1.1.1", listenerEvents[0].getMember().getHost());
    InetAddress addr = InetAddress.getLocalHost();
    location = new ServerLocation(addr.getHostAddress(), 0);
    listenerEvents[0] = null;
    InternalClientMembership.notifyServerJoined(location);
    Awaitility.await("wait for listener notification").atMost(10, TimeUnit.SECONDS).until(() -> {
        synchronized (listenerEvents) {
            return listenerEvents[0] != null;
        }
    });
    assertEquals(addr.getCanonicalHostName(), listenerEvents[0].getMember().getHost());
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) InetAddress(java.net.InetAddress) ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

ClientMembershipListener (org.apache.geode.management.membership.ClientMembershipListener)14 ClientMembershipEvent (org.apache.geode.management.membership.ClientMembershipEvent)11 Properties (java.util.Properties)7 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)7 AttributesFactory (org.apache.geode.cache.AttributesFactory)6 Region (org.apache.geode.cache.Region)6 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 VM (org.apache.geode.test.dunit.VM)6 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)6 Test (org.junit.Test)6 Host (org.apache.geode.test.dunit.Host)5 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)5 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 MembershipEvent (org.apache.geode.management.membership.MembershipEvent)4 UniversalMembershipListenerAdapter (org.apache.geode.management.membership.UniversalMembershipListenerAdapter)4 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)3 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)3 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)3 MembershipListener (org.apache.geode.management.membership.MembershipListener)3