Search in sources :

Example 1 with HighPriorityAckedMessage

use of org.apache.geode.distributed.internal.HighPriorityAckedMessage in project geode by apache.

the class GMSMembershipManagerJUnitTest method testDirectChannelSendFailureDueToForcedDisconnect.

@Test
public void testDirectChannelSendFailureDueToForcedDisconnect() throws Exception {
    setUpDirectChannelMock();
    HighPriorityAckedMessage m = new HighPriorityAckedMessage();
    InternalDistributedMember[] recipients = new InternalDistributedMember[] { mockMembers[2], mockMembers[3] };
    m.setRecipients(Arrays.asList(recipients));
    Set<InternalDistributedMember> failures = manager.directChannelSend(recipients, m, null);
    manager.setShutdown();
    ConnectExceptions exception = new ConnectExceptions();
    exception.addFailure(recipients[0], new Exception("testing"));
    when(dc.send(any(GMSMembershipManager.class), any(mockMembers.getClass()), any(DistributionMessage.class), anyInt(), anyInt())).thenThrow(exception);
    Assertions.assertThatThrownBy(() -> {
        manager.directChannelSend(recipients, m, null);
    }).isInstanceOf(DistributedSystemDisconnectedException.class);
}
Also used : HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ConnectExceptions(org.apache.geode.internal.tcp.ConnectExceptions) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with HighPriorityAckedMessage

use of org.apache.geode.distributed.internal.HighPriorityAckedMessage in project geode by apache.

the class GMSMembershipManagerJUnitTest method testStartupEvents.

@Test
public void testStartupEvents() throws Exception {
    manager.start();
    manager.started();
    manager.isJoining = true;
    List<InternalDistributedMember> viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], myMemberId });
    manager.installView(new NetView(myMemberId, 2, viewmembers));
    // add a surprise member that will be shunned due to it's having
    // an old view ID
    InternalDistributedMember surpriseMember = mockMembers[2];
    surpriseMember.setVmViewId(1);
    manager.handleOrDeferSurpriseConnect(surpriseMember);
    assertEquals(1, manager.getStartupEvents().size());
    // add a surprise member that will be accepted
    InternalDistributedMember surpriseMember2 = mockMembers[3];
    surpriseMember2.setVmViewId(3);
    manager.handleOrDeferSurpriseConnect(surpriseMember2);
    assertEquals(2, manager.getStartupEvents().size());
    // suspect a member
    InternalDistributedMember suspectMember = mockMembers[1];
    manager.handleOrDeferSuspect(new SuspectMember(mockMembers[0], suspectMember, "testing"));
    // suspect messages aren't queued - they're ignored before joining the system
    assertEquals(2, manager.getStartupEvents().size());
    verify(listener, never()).memberSuspect(suspectMember, mockMembers[0], "testing");
    HighPriorityAckedMessage m = new HighPriorityAckedMessage();
    mockMembers[0].setVmViewId(1);
    m.setRecipient(mockMembers[0]);
    m.setSender(mockMembers[1]);
    manager.handleOrDeferMessage(m);
    assertEquals(3, manager.getStartupEvents().size());
    // this view officially adds surpriseMember2
    viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], myMemberId, surpriseMember2 });
    manager.handleOrDeferViewEvent(new NetView(myMemberId, 3, viewmembers));
    assertEquals(4, manager.getStartupEvents().size());
    // add a surprise member that will be shunned due to it's having
    // an old view ID
    InternalDistributedMember surpriseMember3 = mockMembers[4];
    surpriseMember.setVmViewId(1);
    manager.handleOrDeferSurpriseConnect(surpriseMember);
    assertEquals(5, manager.getStartupEvents().size());
    // process a new view after we finish joining but before event processing has started
    manager.isJoining = false;
    mockMembers[4].setVmViewId(4);
    viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], myMemberId, surpriseMember2, mockMembers[4] });
    manager.handleOrDeferViewEvent(new NetView(myMemberId, 4, viewmembers));
    assertEquals(6, manager.getStartupEvents().size());
    // exercise the toString methods for code coverage
    for (StartupEvent ev : manager.getStartupEvents()) {
        ev.toString();
    }
    manager.startEventProcessing();
    // all startup events should have been processed
    assertEquals(0, manager.getStartupEvents().size());
    // the new view should have been installed
    assertEquals(4, manager.getView().getViewId());
    // supriseMember2 should have been announced
    verify(listener).newMemberConnected(surpriseMember2);
    // supriseMember should have been rejected (old view ID)
    verify(listener, never()).newMemberConnected(surpriseMember);
    // for code coverage also install a view after we finish joining but before
    // event processing has started. This should notify the distribution manager
    // with a LocalViewMessage to process the view
    reset(listener);
    manager.handleOrDeferViewEvent(new NetView(myMemberId, 5, viewmembers));
    assertEquals(0, manager.getStartupEvents().size());
    verify(listener).messageReceived(isA(LocalViewMessage.class));
    // process a suspect now - it will be passed to the listener
    reset(listener);
    suspectMember = mockMembers[1];
    manager.handleOrDeferSuspect(new SuspectMember(mockMembers[0], suspectMember, "testing"));
    verify(listener).memberSuspect(suspectMember, mockMembers[0], "testing");
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) SuspectMember(org.apache.geode.distributed.internal.membership.gms.SuspectMember) StartupEvent(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager.StartupEvent) NetView(org.apache.geode.distributed.internal.membership.NetView) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with HighPriorityAckedMessage

use of org.apache.geode.distributed.internal.HighPriorityAckedMessage in project geode by apache.

the class LocatorDUnitTest method testLeadAndCoordFailure.

/**
   * test lead member and coordinator failure with network partition detection enabled. It would be
   * nice for this test to have more than two "server" vms, to demonstrate that they all exit when
   * the leader and potential- coordinator both disappear in the loss-correlation-window, but there
   * are only four vms available for dunit testing.
   * <p>
   * So, we start two locators with admin distributed systems, then start two regular distributed
   * members.
   * <p>
   * We kill the second locator (which is not the view coordinator) and then kill the non-lead
   * member. That should be okay - the lead and remaining locator continue to run.
   * <p>
   * We then kill the lead member and demonstrate that the original locator (which is now the sole
   * remaining member) shuts itself down.
   */
@Test
public void testLeadAndCoordFailure() throws Exception {
    IgnoredException.addIgnoredException("Possible loss of quorum due");
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM locvm = host.getVM(3);
    Locator locator = null;
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    final int port1 = ports[0];
    this.port1 = port1;
    final int port2 = ports[1];
    DistributedTestUtils.deleteLocatorStateFile(port1, port2);
    final String host0 = NetworkUtils.getServerHostName(host);
    final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
    final Properties properties = new Properties();
    properties.put(MCAST_PORT, "0");
    properties.put(LOCATORS, locators);
    properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "true");
    properties.put(DISABLE_AUTO_RECONNECT, "true");
    properties.put(MEMBER_TIMEOUT, "2000");
    properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
    // properties.put("log-level", "fine");
    properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
    addDSProps(properties);
    try {
        final String uname = getUniqueName();
        File logFile = new File("");
        locator = Locator.startLocatorAndDS(port1, logFile, properties);
        final DistributedSystem sys = locator.getDistributedSystem();
        sys.getLogWriter().info("<ExpectedException action=add>java.net.ConnectException</ExpectedException>");
        MembershipManagerHelper.inhibitForcedDisconnectLogging(true);
        locvm.invoke(new SerializableRunnable() {

            public void run() {
                File lf = new File("");
                try {
                    Locator.startLocatorAndDS(port2, lf, properties);
                } catch (IOException ios) {
                    org.apache.geode.test.dunit.Assert.fail("Unable to start locator2", ios);
                }
            }
        });
        Object[] connectArgs = new Object[] { properties };
        SerializableRunnable crashLocator = new SerializableRunnable("Crash locator") {

            public void run() {
                Locator loc = Locator.getLocators().iterator().next();
                DistributedSystem msys = loc.getDistributedSystem();
                MembershipManagerHelper.crashDistributedSystem(msys);
                loc.stop();
            }
        };
        assertTrue(MembershipManagerHelper.getLeadMember(sys) == null);
        // properties.put("log-level", getDUnitLogLevel());
        DistributedMember mem1 = (DistributedMember) vm1.invoke(this.getClass(), "getDistributedMember", connectArgs);
        vm2.invoke(this.getClass(), "getDistributedMember", connectArgs);
        assertLeadMember(mem1, sys, 5000);
        assertEquals(sys.getDistributedMember(), MembershipManagerHelper.getCoordinator(sys));
        // crash the second vm and the locator. Should be okay
        DistributedTestUtils.crashDistributedSystem(vm2);
        locvm.invoke(crashLocator);
        assertTrue("Distributed system should not have disconnected", vm1.invoke(() -> LocatorDUnitTest.isSystemConnected()));
        // ensure quorumLost is properly invoked
        DistributionManager dm = (DistributionManager) ((InternalDistributedSystem) sys).getDistributionManager();
        MyMembershipListener listener = new MyMembershipListener();
        dm.addMembershipListener(listener);
        // ensure there is an unordered reader thread for the member
        new HighPriorityAckedMessage().send(Collections.singleton(mem1), false);
        // disconnect the first vm and demonstrate that the third vm and the
        // locator notice the failure and exit
        DistributedTestUtils.crashDistributedSystem(vm1);
        /*
       * This vm is watching vm1, which is watching vm2 which is watching locvm. It will take 3 * (3
       * * member-timeout) milliseconds to detect the full failure and eject the lost members from
       * the view.
       */
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("waiting for my distributed system to disconnect due to partition detection");
        Awaitility.waitAtMost(24000, TimeUnit.MILLISECONDS).pollInterval(200, TimeUnit.MILLISECONDS).until(() -> {
            return !sys.isConnected();
        });
        if (sys.isConnected()) {
            fail("Distributed system did not disconnect as expected - network partition detection is broken");
        }
        // quorumLost should be invoked if we get a ForcedDisconnect in this situation
        assertTrue("expected quorumLost to be invoked", listener.quorumLostInvoked);
        assertTrue("expected suspect processing initiated by TCPConduit", listener.suspectReasons.contains(Connection.INITIATING_SUSPECT_PROCESSING));
    } finally {
        if (locator != null) {
            locator.stop();
        }
        LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
        bLogger.info("<ExpectedException action=remove>service failure</ExpectedException>");
        bLogger.info("<ExpectedException action=remove>java.net.ConnectException</ExpectedException>");
        bLogger.info("<ExpectedException action=remove>org.apache.geode.ForcedDisconnectException</ExpectedException>");
        disconnectAllFromDS();
    }
}
Also used : HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) Properties(java.util.Properties) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LogWriter(org.apache.geode.LogWriter) VM(org.apache.geode.test.dunit.VM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) File(java.io.File) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 4 with HighPriorityAckedMessage

use of org.apache.geode.distributed.internal.HighPriorityAckedMessage in project geode by apache.

the class GMSMembershipManagerJUnitTest method testDirectChannelSendAllRecipients.

@Test
public void testDirectChannelSendAllRecipients() throws Exception {
    setUpDirectChannelMock();
    HighPriorityAckedMessage m = new HighPriorityAckedMessage();
    m.setRecipient(DistributionMessage.ALL_RECIPIENTS);
    assertTrue(m.forAll());
    Set<InternalDistributedMember> failures = manager.directChannelSend(null, m, null);
    assertTrue(failures == null);
    verify(dc).send(isA(GMSMembershipManager.class), isA(mockMembers.getClass()), isA(DistributionMessage.class), anyInt(), anyInt());
}
Also used : HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with HighPriorityAckedMessage

use of org.apache.geode.distributed.internal.HighPriorityAckedMessage in project geode by apache.

the class GMSMembershipManagerJUnitTest method testDirectChannelSend.

@Test
public void testDirectChannelSend() throws Exception {
    setUpDirectChannelMock();
    HighPriorityAckedMessage m = new HighPriorityAckedMessage();
    InternalDistributedMember[] recipients = new InternalDistributedMember[] { mockMembers[2], mockMembers[3] };
    m.setRecipients(Arrays.asList(recipients));
    Set<InternalDistributedMember> failures = manager.directChannelSend(recipients, m, null);
    assertTrue(failures == null);
    verify(dc).send(isA(GMSMembershipManager.class), isA(mockMembers.getClass()), isA(DistributionMessage.class), anyInt(), anyInt());
}
Also used : HighPriorityAckedMessage(org.apache.geode.distributed.internal.HighPriorityAckedMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

HighPriorityAckedMessage (org.apache.geode.distributed.internal.HighPriorityAckedMessage)9 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)9 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)9 Test (org.junit.Test)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)8 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)5 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)3 NetView (org.apache.geode.distributed.internal.membership.NetView)3 ConnectExceptions (org.apache.geode.internal.tcp.ConnectExceptions)2 File (java.io.File)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 LogWriter (org.apache.geode.LogWriter)1 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)1 SuspectMember (org.apache.geode.distributed.internal.membership.gms.SuspectMember)1 StartupEvent (org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager.StartupEvent)1 InternalLogWriter (org.apache.geode.internal.logging.InternalLogWriter)1 LocalLogWriter (org.apache.geode.internal.logging.LocalLogWriter)1