Search in sources :

Example 1 with Manager

use of org.apache.geode.distributed.internal.membership.gms.interfaces.Manager in project geode by apache.

the class StatRecorderJUnitTest method recorderHandlesRejectedExecution.

@Test
public void recorderHandlesRejectedExecution() throws Exception {
    Message msg = mock(Message.class);
    when(msg.getHeader(any(Short.class))).thenReturn(Header.createDataHeader(1L, (short) 1, true));
    when(msg.size()).thenReturn(150L);
    // GEODE-1178, the TP protocol may throw a RejectedExecutionException & StatRecorder should
    // retry
    when(mockDownProtocol.down(any(Event.class))).thenThrow(new RejectedExecutionException());
    // after the first down() throws an exception we want StatRecorder to retry, so
    // we set the Manager to say no shutdown is in progress the first time and then say
    // one IS in progress so we can break out of the StatRecorder exception handling loop
    when(services.getCancelCriterion()).thenReturn(new Services().getCancelCriterion());
    Manager manager = mock(Manager.class);
    when(services.getManager()).thenReturn(manager);
    when(manager.shutdownInProgress()).thenReturn(Boolean.FALSE, Boolean.TRUE);
    verify(mockDownProtocol, never()).down(isA(Event.class));
    Event evt = new Event(Event.MSG, msg);
    recorder.down(evt);
    verify(mockDownProtocol, times(2)).down(isA(Event.class));
}
Also used : Services(org.apache.geode.distributed.internal.membership.gms.Services) Message(org.jgroups.Message) Event(org.jgroups.Event) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Manager(org.apache.geode.distributed.internal.membership.gms.interfaces.Manager) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 2 with Manager

use of org.apache.geode.distributed.internal.membership.gms.interfaces.Manager in project geode by apache.

the class GMSJoinLeaveJUnitTest method initMocks.

public void initMocks(boolean enableNetworkPartition, boolean useTestGMSJoinLeave) throws UnknownHostException {
    mockDistConfig = mock(DistributionConfig.class);
    when(mockDistConfig.getEnableNetworkPartitionDetection()).thenReturn(enableNetworkPartition);
    when(mockDistConfig.getLocators()).thenReturn("localhost[8888]");
    when(mockDistConfig.getSecurityUDPDHAlgo()).thenReturn("");
    mockConfig = mock(ServiceConfig.class);
    when(mockDistConfig.getStartLocator()).thenReturn("localhost[12345]");
    when(mockConfig.getDistributionConfig()).thenReturn(mockDistConfig);
    when(mockDistConfig.getLocators()).thenReturn("localhost[12345]");
    when(mockDistConfig.getMcastPort()).thenReturn(0);
    when(mockDistConfig.getMemberTimeout()).thenReturn(2000);
    authenticator = mock(Authenticator.class);
    gmsJoinLeaveMemberId = new InternalDistributedMember("localhost", 8887);
    messenger = mock(Messenger.class);
    when(messenger.getMemberID()).thenReturn(gmsJoinLeaveMemberId);
    stopper = mock(Stopper.class);
    when(stopper.isCancelInProgress()).thenReturn(false);
    manager = mock(Manager.class);
    healthMonitor = mock(HealthMonitor.class);
    when(healthMonitor.getFailureDetectionPort()).thenReturn(Integer.valueOf(-1));
    services = mock(Services.class);
    when(services.getAuthenticator()).thenReturn(authenticator);
    when(services.getConfig()).thenReturn(mockConfig);
    when(services.getMessenger()).thenReturn(messenger);
    when(services.getCancelCriterion()).thenReturn(stopper);
    when(services.getManager()).thenReturn(manager);
    when(services.getHealthMonitor()).thenReturn(healthMonitor);
    Timer t = new Timer(true);
    when(services.getTimer()).thenReturn(t);
    mockMembers = new InternalDistributedMember[4];
    for (int i = 0; i < mockMembers.length; i++) {
        mockMembers[i] = new InternalDistributedMember("localhost", 8888 + i);
    }
    mockOldMember = new InternalDistributedMember("localhost", 8700, Version.GFE_56);
    if (useTestGMSJoinLeave) {
        gmsJoinLeave = new GMSJoinLeaveTest();
    } else {
        gmsJoinLeave = new GMSJoinLeave();
    }
    gmsJoinLeave.init(services);
    gmsJoinLeave.start();
    gmsJoinLeave.started();
}
Also used : HealthMonitor(org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor) Messenger(org.apache.geode.distributed.internal.membership.gms.interfaces.Messenger) Manager(org.apache.geode.distributed.internal.membership.gms.interfaces.Manager) Services(org.apache.geode.distributed.internal.membership.gms.Services) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) Stopper(org.apache.geode.distributed.internal.membership.gms.Services.Stopper) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Timer(java.util.Timer) ServiceConfig(org.apache.geode.distributed.internal.membership.gms.ServiceConfig) Authenticator(org.apache.geode.distributed.internal.membership.gms.interfaces.Authenticator)

Example 3 with Manager

use of org.apache.geode.distributed.internal.membership.gms.interfaces.Manager in project geode by apache.

the class GMSJoinLeaveJUnitTest method testForceDisconnectedFromNewView.

@Test
public void testForceDisconnectedFromNewView() throws IOException {
    // enabledNetworkPartition;
    initMocks(true);
    Manager mockManager = mock(Manager.class);
    when(services.getManager()).thenReturn(mockManager);
    prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
    int viewId = 2;
    List<InternalDistributedMember> mbrs = new LinkedList<>();
    mbrs.add(mockMembers[1]);
    mbrs.add(mockMembers[2]);
    mbrs.add(mockMembers[3]);
    // install the view
    NetView netView = new NetView(mockMembers[0], viewId, mbrs);
    InstallViewMessage installViewMessage = getInstallViewMessage(netView, credentials, false);
    gmsJoinLeave.processMessage(installViewMessage);
    Assert.assertNotEquals(netView, gmsJoinLeave.getView());
    verify(mockManager).forceDisconnect(isA(String.class));
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) Manager(org.apache.geode.distributed.internal.membership.gms.interfaces.Manager) LinkedList(java.util.LinkedList) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with Manager

use of org.apache.geode.distributed.internal.membership.gms.interfaces.Manager in project geode by apache.

the class JGroupsMessengerJUnitTest method initMocks.

/**
   * Create stub and mock objects
   */
private void initMocks(boolean enableMcast, Properties addProp) throws Exception {
    if (messenger != null) {
        messenger.stop();
        messenger = null;
    }
    Properties nonDefault = new Properties();
    nonDefault.put(DISABLE_TCP, "true");
    nonDefault.put(MCAST_PORT, enableMcast ? "" + AvailablePortHelper.getRandomAvailableUDPPort() : "0");
    nonDefault.put(MCAST_TTL, "0");
    nonDefault.put(LOG_FILE, "");
    nonDefault.put(LOG_LEVEL, "fine");
    nonDefault.put(LOCATORS, "localhost[10344]");
    nonDefault.put(ACK_WAIT_THRESHOLD, "1");
    nonDefault.putAll(addProp);
    DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
    RemoteTransportConfig tconfig = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    stopper = mock(Stopper.class);
    when(stopper.isCancelInProgress()).thenReturn(false);
    manager = mock(Manager.class);
    when(manager.isMulticastAllowed()).thenReturn(enableMcast);
    healthMonitor = mock(HealthMonitor.class);
    joinLeave = mock(JoinLeave.class);
    ServiceConfig serviceConfig = new ServiceConfig(tconfig, config);
    services = mock(Services.class);
    when(services.getConfig()).thenReturn(serviceConfig);
    when(services.getCancelCriterion()).thenReturn(stopper);
    when(services.getHealthMonitor()).thenReturn(healthMonitor);
    when(services.getManager()).thenReturn(manager);
    when(services.getJoinLeave()).thenReturn(joinLeave);
    DM dm = mock(DM.class);
    InternalDistributedSystem system = InternalDistributedSystem.newInstanceForTesting(dm, nonDefault);
    when(services.getStatistics()).thenReturn(new DistributionStats(system, statsId));
    messenger = new JGroupsMessenger();
    messenger.init(services);
    // if I do this earlier then test this return messenger as null
    when(services.getMessenger()).thenReturn(messenger);
    String jgroupsConfig = messenger.getJGroupsStackConfig();
    int startIdx = jgroupsConfig.indexOf("<org");
    int insertIdx = jgroupsConfig.indexOf('>', startIdx + 4) + 1;
    jgroupsConfig = jgroupsConfig.substring(0, insertIdx) + "<" + InterceptUDP.class.getName() + "/>" + jgroupsConfig.substring(insertIdx);
    messenger.setJGroupsStackConfigForTesting(jgroupsConfig);
    // System.out.println("jgroups config: " + jgroupsConfig);
    messenger.start();
    messenger.started();
    interceptor = (InterceptUDP) messenger.myChannel.getProtocolStack().getTransport().getUpProtocol();
}
Also used : JoinLeave(org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave) HealthMonitor(org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor) DM(org.apache.geode.distributed.internal.DM) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Manager(org.apache.geode.distributed.internal.membership.gms.interfaces.Manager) Services(org.apache.geode.distributed.internal.membership.gms.Services) Stopper(org.apache.geode.distributed.internal.membership.gms.Services.Stopper) ServiceConfig(org.apache.geode.distributed.internal.membership.gms.ServiceConfig) DistributionConfigImpl(org.apache.geode.distributed.internal.DistributionConfigImpl) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionStats(org.apache.geode.distributed.internal.DistributionStats)

Example 5 with Manager

use of org.apache.geode.distributed.internal.membership.gms.interfaces.Manager in project geode by apache.

the class DistributionManagerDUnitTest method testWaitForViewInstallation.

/**
   * install a new view and show that waitForViewInstallation works as expected
   */
@Test
public void testWaitForViewInstallation() {
    getSystem(new Properties());
    MembershipManager mgr = basicGetSystem().getDM().getMembershipManager();
    final NetView v = mgr.getView();
    final boolean[] passed = new boolean[1];
    Thread t = new Thread("wait for view installation") {

        public void run() {
            try {
                ((DistributionManager) basicGetSystem().getDM()).waitForViewInstallation(v.getViewId() + 1);
                synchronized (passed) {
                    passed[0] = true;
                }
            } catch (InterruptedException e) {
            // failed
            }
        }
    };
    t.setDaemon(true);
    t.start();
    Wait.pause(2000);
    NetView newView = new NetView(v, v.getViewId() + 1);
    ((Manager) mgr).installView(newView);
    Wait.pause(2000);
    synchronized (passed) {
        Assert.assertTrue(passed[0]);
    }
}
Also used : NetView(org.apache.geode.distributed.internal.membership.NetView) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedRestoreSystemProperties(org.apache.geode.test.dunit.rules.DistributedRestoreSystemProperties) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) Manager(org.apache.geode.distributed.internal.membership.gms.interfaces.Manager) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

Manager (org.apache.geode.distributed.internal.membership.gms.interfaces.Manager)6 Services (org.apache.geode.distributed.internal.membership.gms.Services)4 Properties (java.util.Properties)3 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 ServiceConfig (org.apache.geode.distributed.internal.membership.gms.ServiceConfig)3 Stopper (org.apache.geode.distributed.internal.membership.gms.Services.Stopper)3 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)3 Test (org.junit.Test)3 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)2 NetView (org.apache.geode.distributed.internal.membership.NetView)2 HealthMonitor (org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor)2 JoinLeave (org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave)2 Messenger (org.apache.geode.distributed.internal.membership.gms.interfaces.Messenger)2 LinkedList (java.util.LinkedList)1 Timer (java.util.Timer)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 DM (org.apache.geode.distributed.internal.DM)1 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)1 DistributionConfigImpl (org.apache.geode.distributed.internal.DistributionConfigImpl)1