Search in sources :

Example 46 with LogWriter

use of org.apache.geode.LogWriter 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)

Example 47 with LogWriter

use of org.apache.geode.LogWriter 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 48 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class QueryIndexUsingXMLDUnitTest method prIndexCreationCheck.

private CacheSerializableRunnable prIndexCreationCheck(final String regionName, final String indexName, final int bucketCount) {
    return new CacheSerializableRunnable("pr IndexCreationCheck " + regionName + " indexName :" + indexName) {

        @Override
        public void run2() {
            Cache cache = getCache();
            LogWriter logger = cache.getLogger();
            PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
            PartitionedIndex index = (PartitionedIndex) region.getIndex().get(indexName);
            assertThat(index).isNotNull();
            logger.info("Current number of buckets indexed: " + index.getNumberOfIndexedBuckets());
            if (bucketCount >= 0) {
                waitForIndexedBuckets(index, bucketCount);
            }
            assertThat(index.isPopulated()).isTrue();
        }
    };
}
Also used : PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LogWriter(org.apache.geode.LogWriter) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Cache(org.apache.geode.cache.Cache)

Example 49 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class DistributionManagerDUnitTest method testKickOutSickMember.

/**
   * Tests that a sick member is kicked out
   */
@Test
public void testKickOutSickMember() throws Exception {
    disconnectAllFromDS();
    IgnoredException.addIgnoredException("10 seconds have elapsed while waiting");
    Host host = Host.getHost(0);
    // VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // in order to set a small ack-wait-threshold, we have to remove the
    // system property established by the dunit harness
    String oldAckWait = (String) System.getProperties().remove(DistributionConfig.GEMFIRE_PREFIX + ACK_WAIT_THRESHOLD);
    try {
        final Properties props = getDistributedSystemProperties();
        // loner
        props.setProperty(MCAST_PORT, "0");
        props.setProperty(ACK_WAIT_THRESHOLD, "5");
        props.setProperty(ACK_SEVERE_ALERT_THRESHOLD, "5");
        props.setProperty(NAME, "putter");
        getSystem(props);
        Region rgn = (new RegionFactory()).setScope(Scope.DISTRIBUTED_ACK).setDataPolicy(DataPolicy.REPLICATE).create("testRegion");
        basicGetSystem().getLogWriter().info("<ExpectedException action=add>sec have elapsed while waiting for replies</ExpectedException>");
        vm1.invoke(new SerializableRunnable("Connect to distributed system") {

            public void run() {
                props.setProperty(NAME, "sleeper");
                getSystem(props);
                LogWriter log = basicGetSystem().getLogWriter();
                log.info("<ExpectedException action=add>service failure</ExpectedException>");
                log.info("<ExpectedException action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
                RegionFactory rf = new RegionFactory();
                Region r = rf.setScope(Scope.DISTRIBUTED_ACK).setDataPolicy(DataPolicy.REPLICATE).addCacheListener(getSleepingListener(true)).create("testRegion");
                myCache = r.getCache();
            }
        });
        // now we have two caches set up, each having an alert listener. Vm1
        // also has a cache listener that will turn off its ability to respond
        // to "are you dead" messages and then sleep
        rgn.put("bomb", "pow!");
        rgn.getCache().close();
        basicGetSystem().getLogWriter().info("<ExpectedException action=remove>sec have elapsed while waiting for replies</ExpectedException>");
        basicGetSystem().disconnect();
        vm1.invoke(new SerializableRunnable("wait for forced disconnect") {

            public void run() {
                // wait a while for the DS to finish disconnecting
                WaitCriterion ev = new WaitCriterion() {

                    public boolean done() {
                        return !basicGetSystem().isConnected();
                    }

                    public String description() {
                        return null;
                    }
                };
                // if this fails it means the sick member wasn't kicked out and something is wrong
                Wait.waitForCriterion(ev, 60 * 1000, 200, true);
                ev = new WaitCriterion() {

                    public boolean done() {
                        return myCache.isClosed();
                    }

                    public String description() {
                        return null;
                    }
                };
                Wait.waitForCriterion(ev, 20 * 1000, 200, false);
                if (!myCache.isClosed()) {
                    if (basicGetSystem().isConnected()) {
                        basicGetSystem().disconnect();
                    }
                    myCache = null;
                    throw new RuntimeException("Test Failed - vm1's cache is not closed");
                }
                if (basicGetSystem().isConnected()) {
                    basicGetSystem().disconnect();
                    throw new RuntimeException("Test Failed - vm1's system should have been disconnected");
                }
                WaitCriterion wc = new WaitCriterion() {

                    public boolean done() {
                        return regionDestroyedInvoked;
                    }

                    public String description() {
                        return "vm1's listener should have received afterRegionDestroyed notification";
                    }
                };
                Wait.waitForCriterion(wc, 30 * 1000, 1000, true);
            }
        });
    } finally {
        if (oldAckWait != null) {
            System.setProperty(DistributionConfig.GEMFIRE_PREFIX + ACK_WAIT_THRESHOLD, oldAckWait);
        }
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) RegionFactory(org.apache.geode.cache.RegionFactory) LogWriter(org.apache.geode.LogWriter) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedRestoreSystemProperties(org.apache.geode.test.dunit.rules.DistributedRestoreSystemProperties) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 50 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class DistributionManagerDUnitTest method getSleepingListener.

static CacheListener getSleepingListener(final boolean playDead) {
    regionDestroyedInvoked = false;
    return new CacheListenerAdapter() {

        @Override
        public void afterCreate(EntryEvent event) {
            try {
                if (playDead) {
                    MembershipManagerHelper.beSickMember(getSystemStatic());
                    MembershipManagerHelper.playDead(getSystemStatic());
                }
                Thread.sleep(15000);
            } catch (InterruptedException ie) {
                fail("interrupted", ie);
            }
        }

        @Override
        public void afterRegionDestroy(RegionEvent event) {
            LogWriter logger = myCache.getLogger();
            logger.info("afterRegionDestroyed invoked in sleeping listener");
            logger.info("<ExpectedException action=remove>service failure</ExpectedException>");
            logger.info("<ExpectedException action=remove>org.apache.geode.ForcedDisconnectException</ExpectedException>");
            regionDestroyedInvoked = true;
        }
    };
}
Also used : CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) LogWriter(org.apache.geode.LogWriter) EntryEvent(org.apache.geode.cache.EntryEvent) RegionEvent(org.apache.geode.cache.RegionEvent)

Aggregations

LogWriter (org.apache.geode.LogWriter)87 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)18 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)17 Host (org.apache.geode.test.dunit.Host)17 Region (org.apache.geode.cache.Region)15 DistributedSystem (org.apache.geode.distributed.DistributedSystem)15 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)15 VM (org.apache.geode.test.dunit.VM)13 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)12 Iterator (java.util.Iterator)11 Set (java.util.Set)11 Cache (org.apache.geode.cache.Cache)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)9 Properties (java.util.Properties)8 InternalLogWriter (org.apache.geode.internal.logging.InternalLogWriter)8 IOException (java.io.IOException)7 HashSet (java.util.HashSet)7