use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class CacheServerLoadMessage method updateLocalLocators.
public void updateLocalLocators() {
List locators = Locator.getLocators();
for (int i = 0; i < locators.size(); i++) {
InternalLocator l = (InternalLocator) locators.get(i);
ServerLocator serverLocator = l.getServerLocatorAdvisee();
if (serverLocator != null) {
serverLocator.updateLoad(location, load, this.clientIds);
}
}
}
use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class GridAdvisorDUnitTest method test2by2.
/**
* Tests 2 controllers and 2 bridge servers
*/
@Test
public void test2by2() throws Exception {
disconnectAllFromDS();
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
List<Keeper> freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPortKeepers(6);
final Keeper keeper1 = freeTCPPorts.get(0);
final int port1 = keeper1.getPort();
final Keeper keeper2 = freeTCPPorts.get(1);
final int port2 = keeper2.getPort();
final Keeper bsKeeper1 = freeTCPPorts.get(2);
final int bsPort1 = bsKeeper1.getPort();
final Keeper bsKeeper2 = freeTCPPorts.get(3);
final int bsPort2 = bsKeeper2.getPort();
final Keeper bsKeeper3 = freeTCPPorts.get(4);
final int bsPort3 = bsKeeper3.getPort();
final Keeper bsKeeper4 = freeTCPPorts.get(5);
final int bsPort4 = bsKeeper4.getPort();
final String host0 = NetworkUtils.getServerHostName(host);
final String locators = host0 + "[" + port1 + "]" + "," + host0 + "[" + port2 + "]";
final Properties dsProps = new Properties();
dsProps.setProperty(LOCATORS, locators);
dsProps.setProperty(MCAST_PORT, "0");
dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
keeper1.release();
vm0.invoke(new SerializableRunnable("Start locator on " + port1) {
public void run() {
File logFile = new File(getUniqueName() + "-locator" + port1 + ".log");
try {
Locator.startLocatorAndDS(port1, logFile, null, dsProps, true, true, null);
} catch (IOException ex) {
Assert.fail("While starting locator on port " + port1, ex);
}
}
});
// try { Thread.currentThread().sleep(4000); } catch (InterruptedException ie) { }
keeper2.release();
vm3.invoke(new SerializableRunnable("Start locators on " + port2) {
public void run() {
File logFile = new File(getUniqueName() + "-locator" + port2 + ".log");
try {
Locator.startLocatorAndDS(port2, logFile, null, dsProps, true, true, "locator2HNFC");
} catch (IOException ex) {
Assert.fail("While starting locator on port " + port2, ex);
}
}
});
SerializableRunnable connect = new SerializableRunnable("Connect to " + locators) {
public void run() {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
CacheFactory.create(DistributedSystem.connect(props));
}
};
vm1.invoke(connect);
vm2.invoke(connect);
SerializableRunnable startBS1 = new SerializableRunnable("start bridgeServer on " + bsPort1) {
public void run() {
try {
Cache c = CacheFactory.getAnyInstance();
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort1);
bs.setGroups(new String[] { "bs1Group1", "bs1Group2" });
bs.start();
} catch (IOException ex) {
RuntimeException re = new RuntimeException();
re.initCause(ex);
throw re;
}
}
};
SerializableRunnable startBS3 = new SerializableRunnable("start bridgeServer on " + bsPort3) {
public void run() {
try {
Cache c = CacheFactory.getAnyInstance();
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort3);
bs.setGroups(new String[] { "bs3Group1", "bs3Group2" });
bs.start();
} catch (IOException ex) {
RuntimeException re = new RuntimeException();
re.initCause(ex);
throw re;
}
}
};
bsKeeper1.release();
vm1.invoke(startBS1);
bsKeeper3.release();
vm1.invoke(startBS3);
bsKeeper2.release();
vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort2) {
public void run() {
try {
Cache c = CacheFactory.getAnyInstance();
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort2);
bs.setGroups(new String[] { "bs2Group1", "bs2Group2" });
bs.start();
} catch (IOException ex) {
RuntimeException re = new RuntimeException();
re.initCause(ex);
throw re;
}
}
});
bsKeeper4.release();
vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort4) {
public void run() {
try {
Cache c = CacheFactory.getAnyInstance();
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort4);
bs.setGroups(new String[] { "bs4Group1", "bs4Group2" });
bs.start();
} catch (IOException ex) {
RuntimeException re = new RuntimeException();
re.initCause(ex);
throw re;
}
}
});
// verify that locators know about each other
vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {
public void run() {
assertTrue(Locator.hasLocator());
InternalLocator l = (InternalLocator) Locator.getLocator();
DistributionAdvisee advisee = l.getServerLocatorAdvisee();
ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
List others = ca.fetchControllers();
assertEquals(1, others.size());
{
ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
assertEquals(port2, cp.getPort());
assertEquals("locator2HNFC", cp.getHost());
}
others = ca.fetchBridgeServers();
assertEquals(4, others.size());
for (int j = 0; j < others.size(); j++) {
CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
if (bsp.getPort() == bsPort1) {
assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort2) {
assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort3) {
assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort4) {
assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
} else {
fail("unexpected port " + bsp.getPort() + " in " + bsp);
}
}
}
});
vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {
public void run() {
assertTrue(Locator.hasLocator());
InternalLocator l = (InternalLocator) Locator.getLocator();
DistributionAdvisee advisee = l.getServerLocatorAdvisee();
ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
List others = ca.fetchControllers();
assertEquals(1, others.size());
{
ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
assertEquals(port1, cp.getPort());
}
others = ca.fetchBridgeServers();
assertEquals(4, others.size());
for (int j = 0; j < others.size(); j++) {
CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
if (bsp.getPort() == bsPort1) {
assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort2) {
assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort3) {
assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort4) {
assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
} else {
fail("unexpected port " + bsp.getPort() + " in " + bsp);
}
}
}
});
vm1.invoke(new SerializableRunnable("Verify bridge server view on " + bsPort1 + " and on " + bsPort3) {
public void run() {
Cache c = CacheFactory.getAnyInstance();
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
List others = bsa.fetchBridgeServers();
LogWriterUtils.getLogWriter().info("found these bridgeservers in " + advisee + ": " + others);
assertEquals(3, others.size());
others = bsa.fetchControllers();
assertEquals(2, others.size());
for (int j = 0; j < others.size(); j++) {
ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
if (cp.getPort() == port1) {
// ok
} else if (cp.getPort() == port2) {
assertEquals("locator2HNFC", cp.getHost());
// ok
} else {
fail("unexpected port " + cp.getPort() + " in " + cp);
}
}
}
}
});
vm2.invoke(new SerializableRunnable("Verify bridge server view on " + bsPort2 + " and on " + bsPort4) {
public void run() {
Cache c = CacheFactory.getAnyInstance();
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
List others = bsa.fetchBridgeServers();
LogWriterUtils.getLogWriter().info("found these bridgeservers in " + advisee + ": " + others);
assertEquals(3, others.size());
others = bsa.fetchControllers();
assertEquals(2, others.size());
for (int j = 0; j < others.size(); j++) {
ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
if (cp.getPort() == port1) {
// ok
} else if (cp.getPort() == port2) {
assertEquals("locator2HNFC", cp.getHost());
// ok
} else {
fail("unexpected port " + cp.getPort() + " in " + cp);
}
}
}
}
});
SerializableRunnable stopBS = new SerializableRunnable("stop bridge server") {
public void run() {
Cache c = CacheFactory.getAnyInstance();
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
CacheServer bs = (CacheServer) bslist.get(0);
bs.stop();
}
};
vm1.invoke(stopBS);
// now check to see if everyone else noticed him going away
vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {
public void run() {
assertTrue(Locator.hasLocator());
InternalLocator l = (InternalLocator) Locator.getLocator();
DistributionAdvisee advisee = l.getServerLocatorAdvisee();
ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
List others = ca.fetchControllers();
assertEquals(1, others.size());
{
ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
assertEquals(port2, cp.getPort());
assertEquals("locator2HNFC", cp.getHost());
}
others = ca.fetchBridgeServers();
assertEquals(3, others.size());
for (int j = 0; j < others.size(); j++) {
CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
if (bsp.getPort() == bsPort2) {
assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort3) {
assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort4) {
assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
} else {
fail("unexpected port " + bsp.getPort() + " in " + bsp);
}
}
}
});
vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {
public void run() {
assertTrue(Locator.hasLocator());
InternalLocator l = (InternalLocator) Locator.getLocator();
DistributionAdvisee advisee = l.getServerLocatorAdvisee();
ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
List others = ca.fetchControllers();
assertEquals(1, others.size());
{
ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
assertEquals(port1, cp.getPort());
}
others = ca.fetchBridgeServers();
assertEquals(3, others.size());
for (int j = 0; j < others.size(); j++) {
CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
if (bsp.getPort() == bsPort2) {
assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort3) {
assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort4) {
assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
} else {
fail("unexpected port " + bsp.getPort() + " in " + bsp);
}
}
}
});
SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {
public void run() {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
DistributedSystem.connect(props).disconnect();
}
};
SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {
public void run() {
assertTrue(Locator.hasLocator());
Locator.getLocator().stop();
assertFalse(Locator.hasLocator());
}
};
vm0.invoke(stopLocator);
// now make sure everyone else saw the locator go away
vm3.invoke(new SerializableRunnable("Verify locator stopped ") {
public void run() {
assertTrue(Locator.hasLocator());
InternalLocator l = (InternalLocator) Locator.getLocator();
DistributionAdvisee advisee = l.getServerLocatorAdvisee();
ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
List others = ca.fetchControllers();
assertEquals(0, others.size());
}
});
vm2.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {
public void run() {
Cache c = CacheFactory.getAnyInstance();
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
List others = bsa.fetchControllers();
assertEquals(1, others.size());
for (int j = 0; j < others.size(); j++) {
ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
if (cp.getPort() == port2) {
assertEquals("locator2HNFC", cp.getHost());
// ok
} else {
fail("unexpected port " + cp.getPort() + " in " + cp);
}
}
}
}
});
vm1.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {
public void run() {
Cache c = CacheFactory.getAnyInstance();
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
if (i == 0) {
// skip this one since it is stopped
continue;
}
CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
List others = bsa.fetchControllers();
assertEquals(1, others.size());
for (int j = 0; j < others.size(); j++) {
ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
if (cp.getPort() == port2) {
assertEquals("locator2HNFC", cp.getHost());
// ok
} else {
fail("unexpected port " + cp.getPort() + " in " + cp);
}
}
}
}
});
SerializableRunnable restartBS = new SerializableRunnable("restart bridge server") {
public void run() {
try {
Cache c = CacheFactory.getAnyInstance();
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
CacheServer bs = (CacheServer) bslist.get(0);
bs.setHostnameForClients("nameForClients");
bs.start();
} catch (IOException ex) {
RuntimeException re = new RuntimeException();
re.initCause(ex);
throw re;
}
}
};
// restart bridge server 1 and see if controller sees it
vm1.invoke(restartBS);
vm3.invoke(new SerializableRunnable("Verify bridge server restart ") {
public void run() {
assertTrue(Locator.hasLocator());
InternalLocator l = (InternalLocator) Locator.getLocator();
DistributionAdvisee advisee = l.getServerLocatorAdvisee();
ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
assertEquals(0, ca.fetchControllers().size());
List others = ca.fetchBridgeServers();
assertEquals(4, others.size());
for (int j = 0; j < others.size(); j++) {
CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
if (bsp.getPort() == bsPort1) {
assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
assertEquals("nameForClients", bsp.getHost());
} else if (bsp.getPort() == bsPort2) {
assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
assertFalse(bsp.getHost().equals("nameForClients"));
} else if (bsp.getPort() == bsPort3) {
assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
} else if (bsp.getPort() == bsPort4) {
assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
} else {
fail("unexpected port " + bsp.getPort() + " in " + bsp);
}
}
}
});
vm1.invoke(disconnect);
vm2.invoke(disconnect);
// now make sure controller saw all bridge servers stop
vm3.invoke(new SerializableRunnable("Verify locator stopped ") {
public void run() {
assertTrue(Locator.hasLocator());
InternalLocator l = (InternalLocator) Locator.getLocator();
DistributionAdvisee advisee = l.getServerLocatorAdvisee();
ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
assertEquals(0, ca.fetchControllers().size());
assertEquals(0, ca.fetchBridgeServers().size());
}
});
vm3.invoke(stopLocator);
}
use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class DiskStoreCommandsDUnitTest method testCreateDestroyUpdatesSharedConfig.
/**
* Asserts that creating and destroying disk stores correctly updates the shared configuration.
*/
// GEODE-1406
@Category(FlakyTest.class)
@Test
public void testCreateDestroyUpdatesSharedConfig() {
disconnectAllFromDS();
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
jmxPort = ports[0];
httpPort = ports[1];
try {
jmxHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ignore) {
jmxHost = "localhost";
}
final String groupName = "testDiskStoreSharedConfigGroup";
final String diskStoreName = "testDiskStoreSharedConfigDiskStore";
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "fine");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
locatorProps.setProperty(JMX_MANAGER, "true");
locatorProps.setProperty(JMX_MANAGER_START, "true");
locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
WaitCriterion wc = new WaitCriterion() {
@Override
public boolean done() {
return locator.isSharedConfigurationRunning();
}
@Override
public String description() {
return "Waiting for shared configuration to be started";
}
};
waitForCriterion(wc, 5000, 500, true);
} catch (IOException ioex) {
fail("Unable to create a locator with a shared configuration");
}
}
});
connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
final File diskStoreDir = new File(new File(".").getAbsolutePath(), diskStoreName);
this.filesToBeDeleted.add(diskStoreDir.getAbsolutePath());
VM vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableRunnable() {
@Override
public void run() {
diskStoreDir.mkdirs();
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
getSystem(localProps);
assertNotNull(getCache());
}
});
// Test creating the disk store
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStoreName);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__GROUP, groupName);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskStoreDir.getAbsolutePath());
CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the disk store exists in the shared config
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
assertTrue(xmlFromConfig.contains(diskStoreName));
} catch (Exception e) {
fail("Error occurred in cluster configuration service", e);
}
}
});
// Restart the cache and make sure it has the diskstore
vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableCallable() {
@Override
public Object call() {
getCache().close();
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
getSystem(localProps);
Cache cache = getCache();
assertNotNull(cache);
InternalCache internalCache = (InternalCache) cache;
Collection<DiskStore> diskStoreList = internalCache.listDiskStores();
assertNotNull(diskStoreList);
assertFalse(diskStoreList.isEmpty());
assertTrue(diskStoreList.size() == 1);
for (DiskStore diskStore : diskStoreList) {
assertTrue(diskStore.getName().equals(diskStoreName));
break;
}
return null;
}
});
// Test destroying the disk store
commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStoreName);
commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__GROUP, groupName);
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the disk store was removed from the shared config
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
assertFalse(xmlFromConfig.contains(diskStoreName));
} catch (Exception e) {
fail("Error occurred in cluster configuration service", e);
}
}
});
// Restart the cache and make sure it DOES NOT have the diskstore
vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableCallable() {
@Override
public Object call() {
getCache().close();
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
getSystem(localProps);
Cache cache = getCache();
assertNotNull(cache);
InternalCache internalCache = (InternalCache) cache;
Collection<DiskStore> diskStores = internalCache.listDiskStores();
assertNotNull(diskStores);
assertTrue(diskStores.isEmpty());
return null;
}
});
}
use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class WANTestBase method checkAllSiteMetaData.
public static void checkAllSiteMetaData(Map<Integer, Set<InetSocketAddress>> dsIdToLocatorAddresses) {
List<Locator> locatorsConfigured = Locator.getLocators();
Locator locator = locatorsConfigured.get(0);
Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> {
Map<Integer, Set<DistributionLocatorId>> allSiteMetaData = ((InternalLocator) locator).getlocatorMembershipListener().getAllLocatorsInfo();
for (Map.Entry<Integer, Set<InetSocketAddress>> entry : dsIdToLocatorAddresses.entrySet()) {
Set<DistributionLocatorId> foundLocatorIds = allSiteMetaData.get(entry.getKey());
Set<InetSocketAddress> expectedLocators = entry.getValue();
final Set<InetSocketAddress> foundLocators = foundLocatorIds.stream().map(distributionLocatorId -> new InetSocketAddress(distributionLocatorId.getHostnameForClients(), distributionLocatorId.getPort())).collect(Collectors.toSet());
assertEquals(expectedLocators, foundLocators);
}
});
}
use of org.apache.geode.distributed.internal.InternalLocator in project geode by apache.
the class WANTestBase method checkAllSiteMetaDataFor3Sites.
public static Long checkAllSiteMetaDataFor3Sites(final Map<Integer, Set<String>> dsVsPort) {
Awaitility.await().atMost(50, TimeUnit.SECONDS).until(() -> assertEquals("System is not initialized", true, (getSystemStatic() != null)));
List<Locator> locatorsConfigured = Locator.getLocators();
Locator locator = locatorsConfigured.get(0);
LocatorMembershipListener listener = ((InternalLocator) locator).getlocatorMembershipListener();
if (listener == null) {
fail("No locator membership listener available. WAN is likely not enabled. Is this test in the WAN project?");
}
final Map<Integer, Set<DistributionLocatorId>> allSiteMetaData = listener.getAllLocatorsInfo();
System.out.println("allSiteMetaData : " + allSiteMetaData);
Awaitility.await().atMost(300, TimeUnit.SECONDS).until(() -> {
assertEquals(true, (dsVsPort.size() == allSiteMetaData.size()));
boolean completeFlag = true;
for (Map.Entry<Integer, Set<String>> entry : dsVsPort.entrySet()) {
Set<DistributionLocatorId> locators = allSiteMetaData.get(entry.getKey());
for (String locatorInMetaData : entry.getValue()) {
DistributionLocatorId locatorId = new DistributionLocatorId(locatorInMetaData);
if (!locators.contains(locatorId)) {
completeFlag = false;
break;
}
}
if (false == completeFlag) {
break;
}
}
assertEquals("Expected site Metadata: " + dsVsPort + " but actual meta data: " + allSiteMetaData, true, completeFlag);
});
return System.currentTimeMillis();
}
Aggregations