Search in sources :

Example 1 with GMSMembershipManager

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

the class DistributedSystemDUnitTest method testMembershipPortRangeWithExactThreeValues.

@Test
public void testMembershipPortRangeWithExactThreeValues() throws Exception {
    Properties config = new Properties();
    config.setProperty(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
    config.setProperty(MEMBERSHIP_PORT_RANGE, this.lowerBoundOfPortRange + "-" + this.upperBoundOfPortRange);
    InternalDistributedSystem system = getSystem(config);
    Cache cache = CacheFactory.create(system);
    cache.addCacheServer();
    DistributionManager dm = (DistributionManager) system.getDistributionManager();
    InternalDistributedMember member = dm.getDistributionManagerId();
    GMSMembershipManager gms = (GMSMembershipManager) MembershipManagerHelper.getMembershipManager(system);
    JGroupsMessenger messenger = (JGroupsMessenger) gms.getServices().getMessenger();
    String jgConfig = messenger.getJGroupsStackConfig();
    assertThat(jgConfig).as("expected to find port_range=\"2\" in " + jgConfig).contains("port_range=\"2\"");
    verifyMembershipPortsInRange(member, this.lowerBoundOfPortRange, this.upperBoundOfPortRange);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) JGroupsMessenger(org.apache.geode.distributed.internal.membership.gms.messenger.JGroupsMessenger) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with GMSMembershipManager

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

the class ReconnectedCacheServerDUnitTest method testDefaultCacheServerNotCreatedOnReconnect.

@Test
public void testDefaultCacheServerNotCreatedOnReconnect() {
    assertFalse(Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "autoReconnect-useCacheXMLFile"));
    GemFireCacheImpl gc = (GemFireCacheImpl) this.cache;
    // fool the system into thinking cluster-config is being used
    GMSMembershipManager mgr = (GMSMembershipManager) MembershipManagerHelper.getMembershipManager(gc.getDistributedSystem());
    final boolean sharedConfigEnabled = true;
    mgr.saveCacheXmlForReconnect(sharedConfigEnabled);
    // the cache server config should now be stored in the cache's config
    assertFalse(gc.getCacheServers().isEmpty());
    int numServers = gc.getCacheServers().size();
    assertNotNull(gc.getCacheConfig().getCacheServerCreation());
    InternalDistributedSystem system = gc.getInternalDistributedSystem();
    system.createAndStartCacheServers(gc.getCacheConfig().getCacheServerCreation(), gc);
    assertEquals("found these cache servers:" + gc.getCacheServers(), numServers, gc.getCacheServers().size());
}
Also used : GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with GMSMembershipManager

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

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

the class GMSJoinLeaveTestHelper method getGmsJoinLeave.

private static GMSJoinLeave getGmsJoinLeave() {
    InternalDistributedSystem distributedSystem = getInternalDistributedSystem();
    DM dm = distributedSystem.getDM();
    GMSMembershipManager membershipManager = (GMSMembershipManager) dm.getMembershipManager();
    Services services = membershipManager.getServices();
    return (GMSJoinLeave) services.getJoinLeave();
}
Also used : Services(org.apache.geode.distributed.internal.membership.gms.Services) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) DM(org.apache.geode.distributed.internal.DM) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 5 with GMSMembershipManager

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

the class DistributedSystemDUnitTest method testSpecificTcpPort.

/**
   * test the ability to set the port used to listen for tcp/ip connections
   */
@Test
public void testSpecificTcpPort() throws Exception {
    Properties config = new Properties();
    config.put(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
    config.setProperty(TCP_PORT, String.valueOf(this.tcpPort));
    InternalDistributedSystem system = getSystem(config);
    DistributionManager dm = (DistributionManager) system.getDistributionManager();
    GMSMembershipManager mgr = (GMSMembershipManager) dm.getMembershipManager();
    assertThat(mgr.getDirectChannelPort()).isEqualTo(this.tcpPort);
}
Also used : GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

GMSMembershipManager (org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager)10 Test (org.junit.Test)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 Properties (java.util.Properties)5 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)5 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)5 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)4 File (java.io.File)3 InetAddress (java.net.InetAddress)2 Locator (org.apache.geode.distributed.Locator)2 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 JoinLeave (org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave)2 GMSJoinLeave (org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave)2 RemoteTransportConfig (org.apache.geode.internal.admin.remote.RemoteTransportConfig)2 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)2 Cache (org.apache.geode.cache.Cache)1 DM (org.apache.geode.distributed.internal.DM)1 MembershipManager (org.apache.geode.distributed.internal.membership.MembershipManager)1 Services (org.apache.geode.distributed.internal.membership.gms.Services)1