Search in sources :

Example 1 with ServiceConfig

use of org.apache.geode.distributed.internal.membership.gms.ServiceConfig 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 2 with ServiceConfig

use of org.apache.geode.distributed.internal.membership.gms.ServiceConfig 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 3 with ServiceConfig

use of org.apache.geode.distributed.internal.membership.gms.ServiceConfig 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 4 with ServiceConfig

use of org.apache.geode.distributed.internal.membership.gms.ServiceConfig 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 ServiceConfig

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

the class MembershipJUnitTest method testJoinTimeoutSetting.

@Test
public void testJoinTimeoutSetting() throws Exception {
    long timeout = 30000;
    Properties nonDefault = new Properties();
    nonDefault.put(MEMBER_TIMEOUT, "" + timeout);
    DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
    RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    ServiceConfig sc = new ServiceConfig(transport, config);
    assertEquals(2 * timeout + ServiceConfig.MEMBER_REQUEST_COLLECTION_INTERVAL, sc.getJoinTimeout());
    nonDefault.clear();
    config = new DistributionConfigImpl(nonDefault);
    transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    sc = new ServiceConfig(transport, config);
    assertEquals(24000, sc.getJoinTimeout());
    nonDefault.clear();
    nonDefault.put(LOCATORS, SocketCreator.getLocalHost().getHostAddress() + "[" + 12345 + "]");
    config = new DistributionConfigImpl(nonDefault);
    transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    sc = new ServiceConfig(transport, config);
    assertEquals(60000, sc.getJoinTimeout());
    timeout = 2000;
    System.setProperty("p2p.joinTimeout", "" + timeout);
    try {
        config = new DistributionConfigImpl(nonDefault);
        transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
        sc = new ServiceConfig(transport, config);
        assertEquals(timeout, sc.getJoinTimeout());
    } finally {
        System.getProperties().remove("p2p.joinTimeout");
    }
}
Also used : ServiceConfig(org.apache.geode.distributed.internal.membership.gms.ServiceConfig) 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)

Aggregations

Properties (java.util.Properties)5 ServiceConfig (org.apache.geode.distributed.internal.membership.gms.ServiceConfig)5 RemoteTransportConfig (org.apache.geode.internal.admin.remote.RemoteTransportConfig)5 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)4 Services (org.apache.geode.distributed.internal.membership.gms.Services)4 DistributionConfigImpl (org.apache.geode.distributed.internal.DistributionConfigImpl)3 Test (org.junit.Test)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 LinkedList (java.util.LinkedList)1 GemFireConfigException (org.apache.geode.GemFireConfigException)1 DM (org.apache.geode.distributed.internal.DM)1 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)1 DistributionStats (org.apache.geode.distributed.internal.DistributionStats)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 NetView (org.apache.geode.distributed.internal.membership.NetView)1 Stopper (org.apache.geode.distributed.internal.membership.gms.Services.Stopper)1 HealthMonitor (org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor)1 JoinLeave (org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave)1 Manager (org.apache.geode.distributed.internal.membership.gms.interfaces.Manager)1