use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class InterestListEndpointDUnitTest method createCache.
private void createCache(Properties props) throws Exception {
DistributedSystem ds = getSystem(props);
cache = CacheFactory.create(ds);
assertNotNull(cache);
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class InterestListDUnitTest method createCache.
private void createCache(Properties props) throws Exception {
DistributedSystem ds = getSystem(props);
cache = CacheFactory.create(ds);
assertNotNull(cache);
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class InterestListRecoveryDUnitTest method createCache.
private Cache createCache(Properties props) throws Exception {
DistributedSystem ds = getSystem(props);
Cache cache = null;
cache = CacheFactory.create(ds);
if (cache == null) {
throw new Exception("CacheFactory.create() returned null ");
}
return cache;
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class CacheLogRollingIntegrationTest method testStartWithRollingThenRestartWithRolling.
@Test
public void testStartWithRollingThenRestartWithRolling() throws Exception {
Properties config = createConfig();
config.put(LOG_FILE, this.logFile.getAbsolutePath());
config.put(LOG_FILE_SIZE_LIMIT, "1");
this.system = DistributedSystem.connect(config);
logAndRollAndVerify(1);
DistributedSystem firstSystem = this.system;
assertThat(this.logFile).exists();
assertThat(childFile(1, 1)).exists();
assertThat(childFile(1, 2)).exists();
assertThat(childFile(1, 3)).doesNotExist();
assertThat(childFile(2, 1)).doesNotExist();
this.system.disconnect();
config.put(LOG_DISK_SPACE_LIMIT, "200");
this.system = DistributedSystem.connect(config);
assertThat(this.system).isNotSameAs(firstSystem);
assertThat(childFile(1, 3)).exists();
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class ReconnectDUnitTest method doTestReconnectOnForcedDisconnect.
public void doTestReconnectOnForcedDisconnect(final boolean createInAppToo) throws Exception {
IgnoredException.addIgnoredException("killing member's ds");
// getSystem().disconnect();
// getLogWriter().fine("Cache Closed ");
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final int locPort = locatorPort;
final int secondLocPort = AvailablePortHelper.getRandomAvailableTCPPort();
DistributedTestUtils.deleteLocatorStateFile(locPort, secondLocPort);
final String xmlFileLoc = (new File(".")).getAbsolutePath();
SerializableCallable create1 = new SerializableCallable("Create Cache and Regions from cache.xml") {
public Object call() throws CacheException {
// DebuggerSupport.waitForJavaDebugger(getLogWriter(), " about to create region");
locatorPort = locPort;
Properties props = getDistributedSystemProperties();
props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "MyDisconnect-cache.xml");
props.put(MAX_WAIT_TIME_RECONNECT, "1000");
props.put(MAX_NUM_RECONNECT_TRIES, "2");
// props.put("log-file", "autoReconnectVM"+VM.getCurrentVMNum()+"_"+getPID()+".log");
Cache cache = new CacheFactory(props).create();
Region myRegion = cache.getRegion("root/myRegion");
ReconnectDUnitTest.savedSystem = cache.getDistributedSystem();
myRegion.put("MyKey1", "MyValue1");
// myRegion.put("Mykey2", "MyValue2");
return savedSystem.getDistributedMember();
}
};
SerializableCallable create2 = new SerializableCallable("Create Cache and Regions from cache.xml") {
public Object call() throws CacheException {
// DebuggerSupport.waitForJavaDebugger(getLogWriter(), " about to create region");
locatorPort = locPort;
final Properties props = getDistributedSystemProperties();
props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "MyDisconnect-cache.xml");
props.put(MAX_WAIT_TIME_RECONNECT, "5000");
props.put(MAX_NUM_RECONNECT_TRIES, "2");
props.put(START_LOCATOR, "localhost[" + secondLocPort + "]");
props.put(LOCATORS, props.get(LOCATORS) + ",localhost[" + secondLocPort + "]");
// props.put("log-file", "autoReconnectVM"+VM.getCurrentVMNum()+"_"+getPID()+".log");
getSystem(props);
// MembershipManagerHelper.getMembershipManager(system).setDebugJGroups(true);
final Cache cache = getCache();
ReconnectDUnitTest.savedSystem = cache.getDistributedSystem();
Region myRegion = cache.getRegion("root/myRegion");
// myRegion.put("MyKey1", "MyValue1");
myRegion.put("Mykey2", "MyValue2");
assertNotNull(myRegion.get("MyKey1"));
// getLogWriter().fine("MyKey1 value is : "+myRegion.get("MyKey1"));
if (createInAppToo) {
Thread recreateCacheThread = new Thread("ReconnectDUnitTest.createInAppThread") {
public void run() {
while (!cache.isClosed()) {
Wait.pause(100);
}
try {
new CacheFactory(props).create();
LogWriterUtils.getLogWriter().error("testReconnectCollidesWithApplication failed - application thread was able to create a cache");
} catch (IllegalStateException cacheExists) {
// expected
}
}
};
recreateCacheThread.setDaemon(true);
recreateCacheThread.start();
}
return cache.getDistributedSystem().getDistributedMember();
}
};
vm0.invoke(create1);
DistributedMember dm = (DistributedMember) vm1.invoke(create2);
IgnoredException.addIgnoredException("ForcedDisconnectException");
forceDisconnect(vm1);
DistributedMember newdm = (DistributedMember) vm1.invoke(new SerializableCallable("wait for reconnect(1)") {
public Object call() {
final DistributedSystem ds = ReconnectDUnitTest.savedSystem;
ReconnectDUnitTest.savedSystem = null;
Wait.waitForCriterion(new WaitCriterion() {
public boolean done() {
return ds.isReconnecting();
}
public String description() {
return "waiting for ds to begin reconnecting";
}
}, 30000, 1000, true);
LogWriterUtils.getLogWriter().info("entering reconnect wait for " + ds);
LogWriterUtils.getLogWriter().info("ds.isReconnecting() = " + ds.isReconnecting());
boolean failure = true;
try {
ds.waitUntilReconnected(60, TimeUnit.SECONDS);
ReconnectDUnitTest.savedSystem = ds.getReconnectedSystem();
InternalLocator locator = (InternalLocator) Locator.getLocator();
assertTrue("Expected system to be restarted", ds.getReconnectedSystem() != null);
assertTrue("Expected system to be running", ds.getReconnectedSystem().isConnected());
assertTrue("Expected there to be a locator", locator != null);
assertTrue("Expected locator to be restarted", !locator.isStopped());
failure = false;
return ds.getReconnectedSystem().getDistributedMember();
} catch (InterruptedException e) {
LogWriterUtils.getLogWriter().warning("interrupted while waiting for reconnect");
return null;
} finally {
if (failure) {
ds.disconnect();
}
}
}
});
assertNotSame(dm, newdm);
// force another reconnect and show that stopReconnecting works
forceDisconnect(vm1);
boolean stopped = (Boolean) vm1.invoke(new SerializableCallable("wait for reconnect and stop") {
public Object call() {
final DistributedSystem ds = ReconnectDUnitTest.savedSystem;
ReconnectDUnitTest.savedSystem = null;
Wait.waitForCriterion(new WaitCriterion() {
public boolean done() {
return ds.isReconnecting() || ds.getReconnectedSystem() != null;
}
public String description() {
return "waiting for reconnect to commence in " + ds;
}
}, 10000, 1000, true);
ds.stopReconnecting();
assertFalse(ds.isReconnecting());
DistributedSystem newDs = InternalDistributedSystem.getAnyInstance();
if (newDs != null) {
LogWriterUtils.getLogWriter().warning("expected distributed system to be disconnected: " + newDs);
newDs.disconnect();
return false;
}
return true;
}
});
assertTrue("expected DistributedSystem to disconnect", stopped);
// recreate the system in vm1 without a locator and crash it
dm = (DistributedMember) vm1.invoke(create1);
forceDisconnect(vm1);
newdm = waitForReconnect(vm1);
assertNotSame("expected a reconnect to occur in member", dm, newdm);
DistributedTestUtils.deleteLocatorStateFile(locPort);
DistributedTestUtils.deleteLocatorStateFile(secondLocPort);
}
Aggregations