Search in sources :

Example 1 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.

the class StatRecorderJUnitTest method messengerStackHoldsStatRecorder.

/**
   * Ensure that the messenger JGroups configuration XML strings contain the statistics recorder
   * protocol
   */
@Test
public void messengerStackHoldsStatRecorder() throws Exception {
    Services mockServices = mock(Services.class);
    ServiceConfig mockConfig = mock(ServiceConfig.class);
    when(mockServices.getConfig()).thenReturn(mockConfig);
    // first test to see if the non-multicast stack has the recorder installed
    Properties nonDefault = new Properties();
    nonDefault.put(MCAST_PORT, "0");
    nonDefault.put(LOCATORS, "localhost[12345]");
    DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
    when(mockConfig.getDistributionConfig()).thenReturn(config);
    RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    when(mockConfig.getTransport()).thenReturn(transport);
    JGroupsMessenger messenger = new JGroupsMessenger();
    messenger.init(mockServices);
    String jgroupsConfig = messenger.getJGroupsStackConfig();
    System.out.println(jgroupsConfig);
    assertTrue(jgroupsConfig.contains("gms.messenger.StatRecorder"));
    // now test to see if the multicast stack has the recorder installed
    nonDefault.put(MCAST_PORT, "12345");
    config = new DistributionConfigImpl(nonDefault);
    transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    when(mockConfig.getDistributionConfig()).thenReturn(config);
    when(mockConfig.getTransport()).thenReturn(transport);
    messenger = new JGroupsMessenger();
    messenger.init(mockServices);
    assertTrue(jgroupsConfig.contains("gms.messenger.StatRecorder"));
}
Also used : Services(org.apache.geode.distributed.internal.membership.gms.Services) ServiceConfig(org.apache.geode.distributed.internal.membership.gms.ServiceConfig) DistributionConfigImpl(org.apache.geode.distributed.internal.DistributionConfigImpl) JGroupsMessenger(org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) Properties(java.util.Properties) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 2 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.

the class GMSEncryptJUnitTest method initMocks.

private void initMocks(String algo) throws Exception {
    Properties nonDefault = new Properties();
    nonDefault.put(ConfigurationProperties.SECURITY_UDP_DHALGO, algo);
    DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
    RemoteTransportConfig tconfig = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    ServiceConfig serviceConfig = new ServiceConfig(tconfig, config);
    services = mock(Services.class);
    when(services.getConfig()).thenReturn(serviceConfig);
    mockMembers = new InternalDistributedMember[4];
    for (int i = 0; i < mockMembers.length; i++) {
        mockMembers[i] = new InternalDistributedMember("localhost", 8888 + i);
    }
    int viewId = 1;
    List<InternalDistributedMember> mbrs = new LinkedList<>();
    mbrs.add(mockMembers[0]);
    mbrs.add(mockMembers[1]);
    mbrs.add(mockMembers[2]);
    // prepare the view
    netView = new NetView(mockMembers[0], viewId, mbrs);
}
Also used : Services(org.apache.geode.distributed.internal.membership.gms.Services) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ServiceConfig(org.apache.geode.distributed.internal.membership.gms.ServiceConfig) DistributionConfigImpl(org.apache.geode.distributed.internal.DistributionConfigImpl) NetView(org.apache.geode.distributed.internal.membership.NetView) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) LinkedList(java.util.LinkedList)

Example 3 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.

the class MembershipJUnitTest method doTestMultipleManagersInSameProcessWithGroups.

/**
   * this runs the test with a given set of member groups. Returns the groups of the member that was
   * not the coordinator for verification that they were correctly transmitted
   */
private List<String> doTestMultipleManagersInSameProcessWithGroups(String groups) throws Exception {
    MembershipManager m1 = null, m2 = null;
    Locator l = null;
    try {
        // boot up a locator
        int port = AvailablePortHelper.getRandomAvailableTCPPort();
        InetAddress localHost = SocketCreator.getLocalHost();
        // this locator will hook itself up with the first MembershipManager
        // to be created
        l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, new Properties(), null);
        // create configuration objects
        Properties nonDefault = new Properties();
        nonDefault.put(DISABLE_TCP, "true");
        nonDefault.put(MCAST_PORT, "0");
        nonDefault.put(LOG_FILE, "");
        nonDefault.put(LOG_LEVEL, "fine");
        nonDefault.put(GROUPS, groups);
        nonDefault.put(MEMBER_TIMEOUT, "2000");
        nonDefault.put(LOCATORS, localHost.getHostName() + '[' + port + ']');
        DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
        RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
        // start the first membership manager
        try {
            System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY, "true");
            DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
            DMStats stats1 = mock(DMStats.class);
            System.out.println("creating 1st membership manager");
            m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
            m1.startEventProcessing();
        } finally {
            System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
        }
        // start the second membership manager
        DistributedMembershipListener listener2 = mock(DistributedMembershipListener.class);
        DMStats stats2 = mock(DMStats.class);
        System.out.println("creating 2nd membership manager");
        m2 = MemberFactory.newMembershipManager(listener2, config, transport, stats2);
        m2.startEventProcessing();
        // we have to check the views with JoinLeave because the membership
        // manager queues new views for processing through the DM listener,
        // which is a mock object in this test
        System.out.println("waiting for views to stabilize");
        JoinLeave jl1 = ((GMSMembershipManager) m1).getServices().getJoinLeave();
        JoinLeave jl2 = ((GMSMembershipManager) m2).getServices().getJoinLeave();
        long giveUp = System.currentTimeMillis() + 15000;
        for (; ; ) {
            try {
                assertTrue("view = " + jl2.getView(), jl2.getView().size() == 2);
                assertTrue("view = " + jl1.getView(), jl1.getView().size() == 2);
                assertTrue(jl1.getView().getCreator().equals(jl2.getView().getCreator()));
                assertTrue(jl1.getView().getViewId() == jl2.getView().getViewId());
                break;
            } catch (AssertionError e) {
                if (System.currentTimeMillis() > giveUp) {
                    throw e;
                }
            }
        }
        NetView view = jl1.getView();
        InternalDistributedMember notCreator;
        if (view.getCreator().equals(jl1.getMemberID())) {
            notCreator = view.getMembers().get(1);
        } else {
            notCreator = view.getMembers().get(0);
        }
        List<String> result = notCreator.getGroups();
        System.out.println("sending SerialAckedMessage from m1 to m2");
        SerialAckedMessage msg = new SerialAckedMessage();
        msg.setRecipient(m2.getLocalMember());
        msg.setMulticast(false);
        m1.send(new InternalDistributedMember[] { m2.getLocalMember() }, msg, null);
        giveUp = System.currentTimeMillis() + 15000;
        boolean verified = false;
        Throwable problem = null;
        while (giveUp > System.currentTimeMillis()) {
            try {
                verify(listener2).messageReceived(isA(SerialAckedMessage.class));
                verified = true;
                break;
            } catch (Error e) {
                problem = e;
                Thread.sleep(500);
            }
        }
        if (!verified) {
            AssertionError error = new AssertionError("Expected a message to be received");
            if (problem != null) {
                error.initCause(error);
            }
            throw error;
        }
        // let the managers idle for a while and get used to each other
        // Thread.sleep(4000l);
        m2.shutdown();
        assertTrue(!m2.isConnected());
        assertTrue(m1.getView().size() == 1);
        return result;
    } finally {
        if (m2 != null) {
            m2.shutdown();
        }
        if (m1 != null) {
            m1.shutdown();
        }
        if (l != null) {
            l.stop();
        }
    }
}
Also used : GMSJoinLeave(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave) JoinLeave(org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Locator(org.apache.geode.distributed.Locator) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) InetAddress(java.net.InetAddress) File(java.io.File)

Example 4 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.

the class MembershipJUnitTest method testMulticastDiscoveryNotAllowed.

@Test
public void testMulticastDiscoveryNotAllowed() {
    Properties nonDefault = new Properties();
    nonDefault.put(DISABLE_TCP, "true");
    nonDefault.put(MCAST_PORT, "12345");
    nonDefault.put(LOG_FILE, "");
    nonDefault.put(LOG_LEVEL, "fine");
    nonDefault.put(LOCATORS, "");
    DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
    RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    ServiceConfig serviceConfig = mock(ServiceConfig.class);
    when(serviceConfig.getDistributionConfig()).thenReturn(config);
    when(serviceConfig.getTransport()).thenReturn(transport);
    Services services = mock(Services.class);
    when(services.getConfig()).thenReturn(serviceConfig);
    GMSJoinLeave joinLeave = new GMSJoinLeave();
    try {
        joinLeave.init(services);
        throw new Error("expected a GemFireConfigException to be thrown because no locators are configured");
    } catch (GemFireConfigException e) {
    // expected
    }
}
Also used : Services(org.apache.geode.distributed.internal.membership.gms.Services) ServiceConfig(org.apache.geode.distributed.internal.membership.gms.ServiceConfig) GemFireConfigException(org.apache.geode.GemFireConfigException) GMSJoinLeave(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig 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)

Aggregations

RemoteTransportConfig (org.apache.geode.internal.admin.remote.RemoteTransportConfig)13 Properties (java.util.Properties)9 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)8 ServiceConfig (org.apache.geode.distributed.internal.membership.gms.ServiceConfig)6 Services (org.apache.geode.distributed.internal.membership.gms.Services)5 Test (org.junit.Test)5 DistributionConfigImpl (org.apache.geode.distributed.internal.DistributionConfigImpl)4 JoinLeave (org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 File (java.io.File)3 InetAddress (java.net.InetAddress)3 Locator (org.apache.geode.distributed.Locator)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 GMSJoinLeave (org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave)3 GemFireConfigException (org.apache.geode.GemFireConfigException)2 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)2 DistributedMembershipListener (org.apache.geode.distributed.internal.membership.DistributedMembershipListener)2 Stopper (org.apache.geode.distributed.internal.membership.gms.Services.Stopper)2 HealthMonitor (org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor)2 GMSMembershipManager (org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager)2