Search in sources :

Example 1 with ClientMembershipListener

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

the class ClientMembershipDUnitTest method testUnregisterClientMembershipListener.

/**
   * Tests unregisterClientMembershipListener to ensure that no further events are delivered to
   * unregistered listeners.
   */
@Test
public void testUnregisterClientMembershipListener() throws Exception {
    final boolean[] fired = new boolean[1];
    final DistributedMember[] member = new DistributedMember[1];
    final String[] memberId = new String[1];
    final boolean[] isClient = new boolean[1];
    getSystem();
    ClientMembershipListener listener = new ClientMembershipListener() {

        public void memberJoined(ClientMembershipEvent event) {
            fired[0] = true;
            member[0] = event.getMember();
            memberId[0] = event.getMemberId();
            isClient[0] = event.isClient();
        }

        public void memberLeft(ClientMembershipEvent event) {
        }

        public void memberCrashed(ClientMembershipEvent event) {
        }
    };
    ClientMembership.registerClientMembershipListener(listener);
    // fire event to make sure listener is registered
    DistributedMember clientJoined = new TestDistributedMember("clientJoined");
    InternalClientMembership.notifyClientJoined(clientJoined);
    Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
        return fired[JOINED];
    });
    assertTrue(fired[0]);
    assertEquals(clientJoined, member[0]);
    assertEquals(clientJoined.getId(), memberId[0]);
    assertTrue(isClient[0]);
    resetArraysForTesting(fired, member, memberId, isClient);
    assertFalse(fired[0]);
    assertNull(memberId[0]);
    assertFalse(isClient[0]);
    // unregister and verify listener is not notified
    ClientMembership.unregisterClientMembershipListener(listener);
    InternalClientMembership.notifyClientJoined(clientJoined);
    Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).until(() -> {
        return true;
    });
    assertFalse(fired[0]);
    assertNull(member[0]);
    assertNull(memberId[0]);
    assertFalse(isClient[0]);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 2 with ClientMembershipListener

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

the class ClientMembershipDUnitTest method testClientMembershipEventsInServer.

/**
   * Tests notification of events in server process. Bridge servers detect client joins when the
   * client connects to the server.
   */
@Test
public void testClientMembershipEventsInServer() throws Exception {
    final boolean[] fired = new boolean[3];
    final DistributedMember[] member = new DistributedMember[3];
    final String[] memberId = new String[3];
    final boolean[] isClient = new boolean[3];
    // create and register ClientMembershipListener in controller vm...
    ClientMembershipListener listener = new ClientMembershipListener() {

        public void memberJoined(ClientMembershipEvent event) {
            System.out.println("[testClientMembershipEventsInServer] memberJoined: " + event);
            fired[JOINED] = true;
            member[JOINED] = event.getMember();
            memberId[JOINED] = event.getMemberId();
            isClient[JOINED] = event.isClient();
            assertFalse(fired[LEFT] || fired[CRASHED]);
        }

        public void memberLeft(ClientMembershipEvent event) {
            System.out.println("[testClientMembershipEventsInServer] memberLeft: " + event);
            fired[LEFT] = true;
            member[LEFT] = event.getMember();
            memberId[LEFT] = event.getMemberId();
            isClient[LEFT] = event.isClient();
            assertFalse(fired[JOINED] || fired[CRASHED]);
        }

        public void memberCrashed(ClientMembershipEvent event) {
            System.out.println("[testClientMembershipEventsInServer] memberCrashed: " + event);
            fired[CRASHED] = true;
            member[CRASHED] = event.getMember();
            memberId[CRASHED] = event.getMemberId();
            isClient[CRASHED] = event.isClient();
            assertFalse(fired[JOINED] || fired[LEFT]);
        }
    };
    ClientMembership.registerClientMembershipListener(listener);
    final VM vm0 = Host.getHost(0).getVM(0);
    final String name = this.getUniqueName();
    final int[] ports = new int[1];
    // create BridgeServer in controller vm...
    System.out.println("[testClientMembershipEventsInServer] 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);
    DistributedMember serverMember = getMemberId();
    String serverMemberId = serverMember.toString();
    System.out.println("[testClientMembershipEventsInServer] ports[0]=" + ports[0]);
    System.out.println("[testClientMembershipEventsInServer] serverMemberId=" + serverMemberId);
    System.out.println("[testClientMembershipEventsInServer] serverMember=" + serverMember);
    assertFalse(fired[JOINED]);
    assertNull(member[JOINED]);
    assertNull(memberId[JOINED]);
    assertFalse(isClient[JOINED]);
    assertFalse(fired[LEFT]);
    assertNull(member[LEFT]);
    assertNull(memberId[LEFT]);
    assertFalse(isClient[LEFT]);
    assertFalse(fired[CRASHED]);
    assertNull(member[CRASHED]);
    assertNull(memberId[CRASHED]);
    assertFalse(isClient[CRASHED]);
    // sanity check...
    System.out.println("[testClientMembershipEventsInServer] sanity check");
    DistributedMember test = new TestDistributedMember("test");
    InternalClientMembership.notifyClientJoined(test);
    Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
        return fired[JOINED] || fired[LEFT] || fired[CRASHED];
    });
    assertTrue(fired[JOINED]);
    assertEquals(test, member[JOINED]);
    assertEquals(test.getId(), memberId[JOINED]);
    assertTrue(isClient[JOINED]);
    assertFalse(fired[LEFT]);
    assertNull(member[LEFT]);
    assertNull(memberId[LEFT]);
    assertFalse(isClient[LEFT]);
    assertFalse(fired[CRASHED]);
    assertNull(member[CRASHED]);
    assertNull(memberId[CRASHED]);
    assertFalse(isClient[CRASHED]);
    resetArraysForTesting(fired, member, memberId, isClient);
    final Host host = Host.getHost(0);
    SerializableCallable createConnectionPool = new SerializableCallable("Create connectionPool") {

        public Object call() {
            System.out.println("[testClientMembershipEventsInServer] create bridge client");
            Properties config = new Properties();
            config.setProperty(MCAST_PORT, "0");
            config.setProperty(LOCATORS, "");
            config.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "false");
            properties = config;
            DistributedSystem s = getSystem(config);
            AttributesFactory factory = new AttributesFactory();
            Pool pool = ClientServerTestCase.configureConnectionPool(factory, NetworkUtils.getServerHostName(host), ports, true, -1, 2, null);
            createRegion(name, factory.create());
            assertNotNull(getRootRegion().getSubregion(name));
            // see geode-1078
            assertTrue(s == basicGetSystem());
            return getMemberId();
        }
    };
    // create bridge client in vm0...
    DistributedMember clientMember = (DistributedMember) vm0.invoke(createConnectionPool);
    String clientMemberId = clientMember.toString();
    Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
        return fired[JOINED] || fired[LEFT] || fired[CRASHED];
    });
    System.out.println("[testClientMembershipEventsInServer] assert server detected client join");
    assertTrue(fired[JOINED]);
    assertEquals(member[JOINED] + " should equal " + clientMember, clientMember, member[JOINED]);
    assertEquals(memberId[JOINED] + " should equal " + clientMemberId, clientMemberId, memberId[JOINED]);
    assertTrue(isClient[JOINED]);
    assertFalse(fired[LEFT]);
    assertNull(member[LEFT]);
    assertNull(memberId[LEFT]);
    assertFalse(isClient[LEFT]);
    assertFalse(fired[CRASHED]);
    assertNull(member[CRASHED]);
    assertNull(memberId[CRASHED]);
    assertFalse(isClient[CRASHED]);
    resetArraysForTesting(fired, member, memberId, isClient);
    pauseForClientToJoin();
    vm0.invoke(new SerializableRunnable("Stop bridge client") {

        public void run() {
            System.out.println("[testClientMembershipEventsInServer] Stop bridge client");
            getRootRegion().getSubregion(name).close();
            Map m = PoolManager.getAll();
            Iterator mit = m.values().iterator();
            while (mit.hasNext()) {
                Pool p = (Pool) mit.next();
                p.destroy();
            }
        }
    });
    Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
        return fired[JOINED] || fired[LEFT] || fired[CRASHED];
    });
    System.out.println("[testClientMembershipEventsInServer] assert server detected client left");
    assertFalse(fired[JOINED]);
    assertNull(member[JOINED]);
    assertNull(memberId[JOINED]);
    assertFalse(isClient[JOINED]);
    assertTrue(fired[LEFT]);
    assertEquals(clientMember, member[LEFT]);
    assertEquals(clientMemberId, memberId[LEFT]);
    assertTrue(isClient[LEFT]);
    assertFalse(fired[CRASHED]);
    assertNull(member[CRASHED]);
    assertNull(memberId[CRASHED]);
    assertFalse(isClient[CRASHED]);
    resetArraysForTesting(fired, member, memberId, isClient);
    // reconnect bridge client to test for crashed event
    clientMemberId = vm0.invoke(createConnectionPool).toString();
    Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
        return fired[JOINED] || fired[LEFT] || fired[CRASHED];
    });
    System.out.println("[testClientMembershipEventsInServer] assert server detected client re-join");
    assertTrue(fired[JOINED]);
    assertEquals(clientMember, member[JOINED]);
    assertEquals(clientMemberId, memberId[JOINED]);
    assertTrue(isClient[JOINED]);
    assertFalse(fired[LEFT]);
    assertNull(member[LEFT]);
    assertNull(memberId[LEFT]);
    assertFalse(isClient[LEFT]);
    assertFalse(fired[CRASHED]);
    assertNull(member[CRASHED]);
    assertNull(memberId[CRASHED]);
    assertFalse(isClient[CRASHED]);
    resetArraysForTesting(fired, member, memberId, isClient);
    pauseForClientToJoin();
    ServerConnection.setForceClientCrashEvent(true);
    try {
        vm0.invoke(new SerializableRunnable("Stop bridge client") {

            public void run() {
                System.out.println("[testClientMembershipEventsInServer] Stop bridge client");
                getRootRegion().getSubregion(name).close();
                Map m = PoolManager.getAll();
                Iterator mit = m.values().iterator();
                while (mit.hasNext()) {
                    Pool p = (Pool) mit.next();
                    p.destroy();
                }
            }
        });
        Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
            return fired[JOINED] || fired[LEFT] || fired[CRASHED];
        });
        System.out.println("[testClientMembershipEventsInServer] assert server detected client crashed");
        assertFalse(fired[JOINED]);
        assertNull(member[JOINED]);
        assertNull(memberId[JOINED]);
        assertFalse(isClient[JOINED]);
        assertFalse(fired[LEFT]);
        assertNull(member[LEFT]);
        assertNull(memberId[LEFT]);
        assertFalse(isClient[LEFT]);
        assertTrue(fired[CRASHED]);
        assertEquals(clientMember, member[CRASHED]);
        assertEquals(clientMemberId, memberId[CRASHED]);
        assertTrue(isClient[CRASHED]);
    } finally {
        ServerConnection.setForceClientCrashEvent(false);
    }
}
Also used : 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) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) AttributesFactory(org.apache.geode.cache.AttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) Pool(org.apache.geode.cache.client.Pool) Map(java.util.Map) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 3 with ClientMembershipListener

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

the class CacheServerImpl method start.

@Override
public synchronized void start() throws IOException {
    Assert.assertTrue(this.cache != null);
    this.serialNumber = createSerialNumber();
    if (DynamicRegionFactory.get().isOpen()) {
        // from servers to clients instead of invalidates.
        if (!this.notifyBySubscription) {
            logger.info(LocalizedMessage.create(LocalizedStrings.CacheServerImpl_FORCING_NOTIFYBYSUBSCRIPTION_TO_SUPPORT_DYNAMIC_REGIONS));
            this.notifyBySubscription = true;
        }
    }
    this.advisor = CacheServerAdvisor.createCacheServerAdvisor(this);
    this.loadMonitor = new LoadMonitor(loadProbe, maxConnections, loadPollInterval, FORCE_LOAD_UPDATE_FREQUENCY, advisor);
    List overflowAttributesList = new LinkedList();
    ClientSubscriptionConfig csc = this.getClientSubscriptionConfig();
    overflowAttributesList.add(0, csc.getEvictionPolicy());
    overflowAttributesList.add(1, valueOf(csc.getCapacity()));
    overflowAttributesList.add(2, valueOf(this.port));
    String diskStoreName = csc.getDiskStoreName();
    if (diskStoreName != null) {
        overflowAttributesList.add(3, diskStoreName);
        // indicator to use diskstore
        overflowAttributesList.add(4, true);
    } else {
        overflowAttributesList.add(3, csc.getOverflowDirectory());
        overflowAttributesList.add(4, false);
    }
    this.acceptor = new AcceptorImpl(getPort(), getBindAddress(), getNotifyBySubscription(), getSocketBufferSize(), getMaximumTimeBetweenPings(), this.cache, getMaxConnections(), getMaxThreads(), getMaximumMessageCount(), getMessageTimeToLive(), this.loadMonitor, overflowAttributesList, this.isGatewayReceiver, this.gatewayTransportFilters, this.tcpNoDelay);
    this.acceptor.start();
    this.advisor.handshake();
    this.loadMonitor.start(new ServerLocation(getExternalAddress(), getPort()), acceptor.getStats());
    // TODO : Need to provide facility to enable/disable client health monitoring.
    // Creating ClientHealthMonitoring region.
    // Force initialization on current cache
    ClientHealthMonitoringRegion.getInstance(this.cache);
    this.cache.getLoggerI18n().config(LocalizedStrings.CacheServerImpl_CACHESERVER_CONFIGURATION___0, getConfig());
    /*
     * If the stopped bridge server is restarted, we'll need to re-register the client membership
     * listener. If the listener is already registered it won't be registered as would the case when
     * start() is invoked for the first time.
     */
    ClientMembershipListener[] membershipListeners = ClientMembership.getClientMembershipListeners();
    boolean membershipListenerRegistered = false;
    for (ClientMembershipListener membershipListener : membershipListeners) {
        // just checking by reference as the listener instance is final
        if (listener == membershipListener) {
            membershipListenerRegistered = true;
            break;
        }
    }
    if (!membershipListenerRegistered) {
        ClientMembership.registerClientMembershipListener(listener);
    }
    if (!isGatewayReceiver) {
        InternalDistributedSystem system = this.cache.getInternalDistributedSystem();
        system.handleResourceEvent(ResourceEvent.CACHE_SERVER_START, this);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LoadMonitor(org.apache.geode.cache.server.internal.LoadMonitor) LinkedList(java.util.LinkedList)

Example 4 with ClientMembershipListener

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

the class ManagementAdapter method handleCacheServerStop.

/**
   * Assumption is its a cache server instance. For Gateway receiver there will be a separate method
   * 
   * @param server cache server instance
   */
public void handleCacheServerStop(CacheServer server) {
    if (!isServiceInitialised("handleCacheServerStop")) {
        return;
    }
    CacheServerMBean mbean = (CacheServerMBean) service.getLocalCacheServerMXBean(server.getPort());
    ClientMembershipListener listener = mbean.getBridge().getClientMembershipListener();
    if (listener != null) {
        ClientMembership.unregisterClientMembershipListener(listener);
    }
    mbean.stopMonitor();
    ObjectName cacheServerMBeanName = MBeanJMXAdapter.getClientServiceMBeanName(server.getPort(), internalCache.getDistributedSystem().getDistributedMember());
    service.unregisterMBean(cacheServerMBeanName);
    Notification notification = new Notification(JMXNotificationType.CACHE_SERVER_STOPPED, memberSource, SequenceNumber.next(), System.currentTimeMillis(), ManagementConstants.CACHE_SERVER_STOPPED_PREFIX);
    memberLevelNotifEmitter.sendNotification(notification);
    memberMBeanBridge.setCacheServer(false);
}
Also used : ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName)

Example 5 with ClientMembershipListener

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

the class UniversalMembershipListenerAdapterDUnitTest method doTestServerEventsInPeerSystem.

private void doTestServerEventsInPeerSystem() 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("[testServerEventsInSystemClient] 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("[testServerEventsInSystemClient] 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("[testServerEventsInSystemClient] 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);
    // 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();
    serverProperties.remove(CLUSTER_SSL_ENABLED);
    serverProperties.remove(CLUSTER_SSL_CIPHERS);
    serverProperties.remove(CLUSTER_SSL_PROTOCOLS);
    serverProperties.remove(CLUSTER_SSL_REQUIRE_AUTHENTICATION);
    System.out.println("[testServerEventsInPeerSystem] ports[0]=" + ports[0]);
    System.out.println("[testServerEventsInPeerSystem] serverMemberId=" + serverMemberId);
    System.out.println("[testServerEventsInPeerSystem] serverMember=" + serverMember);
    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);
    // create BridgeServer in vm0...
    SerializableCallable createPeerCache = new SerializableCallable("Create Peer Cache") {

        @Override
        public Object call() {
            System.out.println("[testServerEventsInPeerSystem] Create Peer cache");
            getSystem(serverProperties);
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            Region region = createRegion(name, factory.create());
            assertNotNull(region);
            assertNotNull(getRootRegion().getSubregion(name));
            return basicGetSystem().getDistributedMember();
        }
    };
    DistributedMember peerMember = (DistributedMember) vm0.invoke(createPeerCache);
    String peerMemberId = peerMember.getId();
    System.out.println("[testServerEventsInPeerSystem] peerMemberId=" + peerMemberId);
    System.out.println("[testServerEventsInPeerSystem] peerMember=" + peerMember);
    synchronized (systemListener) {
        if (!firedSystem[JOINED]) {
            systemListener.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    synchronized (adapter) {
        if (!firedAdapter[JOINED]) {
            adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    System.out.println("[testServerEventsInPeerSystem] assert server detected peer join");
    assertArrayFalse(firedSystemDuplicate);
    assertTrue(firedSystem[JOINED]);
    assertEquals(peerMember, memberSystem[JOINED]);
    assertEquals(peerMemberId, 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]);
    assertNotNull(memberAdapter[JOINED]);
    assertNotNull(memberIdAdapter[JOINED]);
    assertEquals(peerMember, memberAdapter[JOINED]);
    assertEquals(peerMemberId, 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);
    LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
    bgexecLogger.info("<ExpectedException action=add>" + "java.io.IOException" + "</ExpectedException>");
    final IgnoredException ex = IgnoredException.addIgnoredException(ServerConnectivityException.class.getName());
    try {
        vm0.invoke(new SerializableRunnable("Disconnect Peer server") {

            public void run() {
                System.out.println("[testServerEventsInPeerSystem] disconnect peer server");
                closeCache();
                disconnectFromDS();
            }
        });
        synchronized (systemListener) {
            if (!firedSystem[LEFT]) {
                systemListener.wait(ASYNC_EVENT_WAIT_MILLIS);
            }
        }
        synchronized (adapter) {
            if (!firedAdapter[LEFT]) {
                adapter.wait(ASYNC_EVENT_WAIT_MILLIS);
            }
        }
    } finally {
        bgexecLogger.info("<ExpectedException action=remove>" + "java.io.IOException" + "</ExpectedException>");
        ex.remove();
    }
    System.out.println("[testServerEventsInPeerSystem] assert server detected peer crashed");
    assertArrayFalse(firedSystemDuplicate);
    assertArrayFalse(firedAdapterDuplicate);
    assertFalse(firedSystem[JOINED]);
    assertNull(memberSystem[JOINED]);
    assertNull(memberIdSystem[JOINED]);
    assertFalse(isClientSystem[JOINED]);
    assertTrue(firedSystem[LEFT]);
    assertEquals(peerMember, memberSystem[LEFT]);
    assertEquals(peerMemberId, memberIdSystem[LEFT]);
    assertFalse(isClientSystem[LEFT]);
    assertFalse(firedSystem[CRASHED]);
    assertNull(memberSystem[CRASHED]);
    assertNull(memberIdSystem[CRASHED]);
    assertFalse(isClientSystem[CRASHED]);
    resetArraysForTesting(firedSystem, memberSystem, memberIdSystem, isClientSystem);
    assertFalse("this intermittently fails", firedAdapter[JOINED]);
    assertNull(memberIdAdapter[JOINED]);
    assertFalse(isClientAdapter[JOINED]);
    // LEFT fired by System listener
    assertTrue(firedAdapter[LEFT]);
    assertEquals(peerMember, memberAdapter[LEFT]);
    assertEquals(peerMemberId, memberIdAdapter[LEFT]);
    assertFalse(isClientAdapter[LEFT]);
    // There won't be an adapter crashed event because since the two VMs
    // are in the same distributed system, and the server's real member
    // id is used now. In this case, two events are sent - one from
    // jgroups (memberDeparted), and one from the server (a memberCrshed).
    // The memberCrashed event is deemed a duplicate and not sent - see
    // UniversalMembershipListenerAdapter.MembershipListener.isDuplicate
    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) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) AttributesFactory(org.apache.geode.cache.AttributesFactory) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) UniversalMembershipListenerAdapter(org.apache.geode.management.membership.UniversalMembershipListenerAdapter) 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) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) MembershipListener(org.apache.geode.management.membership.MembershipListener)

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