use of org.apache.geode.distributed.Locator in project geode by apache.
the class WANTestBase method putRemoteSiteLocators.
public static void putRemoteSiteLocators(int remoteDsId, Set<String> remoteLocators) {
List<Locator> locatorsConfigured = Locator.getLocators();
Locator locator = locatorsConfigured.get(0);
if (remoteLocators != null) {
// Add fake remote locators to the locators map
((InternalLocator) locator).getlocatorMembershipListener().getAllServerLocatorsInfo().put(remoteDsId, remoteLocators);
}
}
use of org.apache.geode.distributed.Locator in project geode by apache.
the class WANTestBase method createSecondRemoteLocatorWithAPI.
public static Integer createSecondRemoteLocatorWithAPI(int dsId, int localPort, int remoteLocPort, String hostnameForClients) throws IOException {
stopOldLocator();
WANTestBase test = new WANTestBase();
int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
Properties props = test.getDistributedSystemProperties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(DISTRIBUTED_SYSTEM_ID, "" + dsId);
props.setProperty(LOCATORS, "localhost[" + localPort + "]");
props.setProperty(REMOTE_LOCATORS, "localhost[" + remoteLocPort + "]");
Locator locator = Locator.startLocatorAndDS(0, null, InetAddress.getByName("localhost"), props, true, true, hostnameForClients);
return locator.getPort();
}
use of org.apache.geode.distributed.Locator in project geode by apache.
the class MembershipJUnitTest method testLocatorAndTwoServersJoinUsingDiffeHellman.
/**
* This test ensures that secure communications are enabled.
*
* This test creates a locator with a colocated membership manager and then creates a second
* manager that joins the system of the first.
*
* It then makes assertions about the state of the membership view, closes one of the managers and
* makes more assertions.
*/
@Test
public void testLocatorAndTwoServersJoinUsingDiffeHellman() throws Exception {
MembershipManager m1 = null, m2 = null;
Locator l = null;
int mcastPort = AvailablePortHelper.getRandomAvailableUDPPort();
try {
// boot up a locator
int port = AvailablePortHelper.getRandomAvailableTCPPort();
InetAddress localHost = SocketCreator.getLocalHost();
Properties p = new Properties();
p.setProperty(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
// this locator will hook itself up with the first MembershipManager
// to be created
l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, p, null);
// create configuration objects
Properties nonDefault = new Properties();
nonDefault.put(DistributionConfig.DISABLE_TCP_NAME, "true");
nonDefault.put(DistributionConfig.MCAST_PORT_NAME, String.valueOf(mcastPort));
nonDefault.put(DistributionConfig.LOG_FILE_NAME, "");
nonDefault.put(DistributionConfig.LOG_LEVEL_NAME, "fine");
nonDefault.put(DistributionConfig.GROUPS_NAME, "red, blue");
nonDefault.put(DistributionConfig.MEMBER_TIMEOUT_NAME, "2000");
nonDefault.put(DistributionConfig.LOCATORS_NAME, localHost.getHostName() + '[' + port + ']');
nonDefault.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
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;
}
}
}
System.out.println("testing multicast availability");
assertTrue(m1.testMulticast());
System.out.println("multicasting SerialAckedMessage from m1 to m2");
SerialAckedMessage msg = new SerialAckedMessage();
msg.setRecipient(m2.getLocalMember());
msg.setMulticast(true);
m1.send(new InternalDistributedMember[] { m2.getLocalMember() }, msg, null);
giveUp = System.currentTimeMillis() + 5000;
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) {
if (problem != null) {
problem.printStackTrace();
}
fail("Expected a multicast message to be received");
}
// 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);
} finally {
if (m2 != null) {
m2.shutdown();
}
if (m1 != null) {
m1.shutdown();
}
if (l != null) {
l.stop();
}
}
}
use of org.apache.geode.distributed.Locator in project geode by apache.
the class InternalDistributedSystemJUnitTest method testStartLocator.
@Test
public void testStartLocator() {
Properties props = new Properties();
int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
props.setProperty(MCAST_PORT, "0");
props.setProperty(START_LOCATOR, "localhost[" + unusedPort + "],server=false,peer=true");
deleteStateFile(unusedPort);
createSystem(props);
Collection locators = Locator.getLocators();
Assert.assertEquals(1, locators.size());
Locator locator = (Locator) locators.iterator().next();
// Assert.assertIndexDetailsEquals("127.0.0.1", locator.getBindAddress().getHostAddress());
// removed this check for ipv6 testing
Assert.assertEquals(unusedPort, locator.getPort().intValue());
deleteStateFile(unusedPort);
}
use of org.apache.geode.distributed.Locator in project geode by apache.
the class DistributionLocatorId method asDistributionLocatorIds.
/**
* Converts a collection of {@link Locator} instances to a collection of DistributionLocatorId
* instances. Note this will use {@link SocketCreator#getLocalHost()} as the host for
* DistributionLocatorId. This is because all instances of Locator are local only.
*
* @param locators collection of Locator instances
* @return collection of DistributionLocatorId instances
* @throws UnknownHostException
* @see Locator
*/
public static Collection<DistributionLocatorId> asDistributionLocatorIds(Collection<Locator> locators) throws UnknownHostException {
if (locators.isEmpty()) {
return Collections.emptyList();
}
Collection<DistributionLocatorId> locatorIds = new ArrayList<DistributionLocatorId>();
for (Locator locator : locators) {
DistributionLocatorId locatorId = new DistributionLocatorId(SocketCreator.getLocalHost(), locator);
locatorIds.add(locatorId);
}
return locatorIds;
}
Aggregations