use of org.apache.geode.LogWriter in project geode by apache.
the class RegionTestCase method remoteTestPostSnapshot.
public void remoteTestPostSnapshot(String name, boolean isController, boolean isRoot) throws CacheException {
assertTrue(preSnapshotRegion.isDestroyed());
try {
preSnapshotRegion.get("0");
fail("Should have thrown a RegionReinitializedException");
} catch (RegionReinitializedException e) {
// pass
}
LogWriter log = getCache().getLogger();
// get new reference to region
Region postSnapshotRegion = isRoot ? getRootRegion(name) : getRootRegion().getSubregion(name);
assertNotNull("Could not get reference to reinitialized region", postSnapshotRegion);
boolean expectData = isController || postSnapshotRegion.getAttributes().getMirrorType().isMirrored() || postSnapshotRegion.getAttributes().getDataPolicy().isPreloaded();
log.info("region has " + postSnapshotRegion.keySet().size() + " entries");
assertEquals(expectData ? MAX_KEYS : 0, postSnapshotRegion.keySet().size());
// gets the data either locally or by netSearch
assertEquals(new Integer(3), postSnapshotRegion.get("3"));
// bug 33311 coverage
if (expectData) {
assertFalse(postSnapshotRegion.containsValueForKey("9"));
assertTrue(postSnapshotRegion.containsKey("9"));
}
}
use of org.apache.geode.LogWriter in project geode by apache.
the class RegionTestCase method testRootSnapshot.
@Test
public void testRootSnapshot() throws IOException, CacheException, ClassNotFoundException {
final String name = this.getUniqueName();
// create region in controller
preSnapshotRegion = createRootRegion(name, getRegionAttributes());
// create region in other VMs if distributed
boolean isDistributed = getRegionAttributes().getScope().isDistributed();
if (isDistributed) {
Invoke.invokeInEveryVM(new CacheSerializableRunnable("create presnapshot region") {
public void run2() throws CacheException {
preSnapshotRegion = createRootRegion(name, getRegionAttributes());
}
});
}
// add data to region in controller
for (int i = 0; i < MAX_KEYS; i++) {
if (i == MAX_KEYS - 1) {
// bug 33311 coverage
preSnapshotRegion.create(String.valueOf(i), null);
} else {
preSnapshotRegion.create(String.valueOf(i), new Integer(i));
}
}
// save snapshot
File file = new File(name + ".snap");
OutputStream out = new FileOutputStream(file);
try {
preSnapshotRegion.saveSnapshot(out);
assertEquals(new Integer(5), preSnapshotRegion.get("5"));
// destroy all data
for (int i = 0; i < MAX_KEYS; i++) {
preSnapshotRegion.destroy(String.valueOf(i));
}
assertTrue(preSnapshotRegion.keySet().size() == 0);
LogWriter log = getCache().getLogger();
log.info("before loadSnapshot");
// DebuggerSupport.waitForJavaDebugger(getLogWriter());
InputStream in = new FileInputStream(file);
preSnapshotRegion.loadSnapshot(in);
log.info("after loadSnapshot");
// test postSnapshot behavior in controller
log.info("before controller remoteTestPostSnapshot");
remoteTestPostSnapshot(name, true, true);
log.info("after controller remoteTestPostSnapshot");
// test postSnapshot behavior in other VMs if distributed
if (isDistributed) {
log.info("before distributed remoteTestPostSnapshot");
Invoke.invokeInEveryVM(new CacheSerializableRunnable("postSnapshot") {
public void run2() throws CacheException {
RegionTestCase.this.remoteTestPostSnapshot(name, false, true);
}
});
log.info("after distributed remoteTestPostSnapshot");
}
} finally {
file.delete();
}
}
use of org.apache.geode.LogWriter in project geode by apache.
the class LocatorDUnitTest method testNoLocator.
/**
* Tests that attempting to connect to a distributed system in which no locator is defined throws
* an exception.
*/
@Test
public void testNoLocator() {
disconnectAllFromDS();
Host host = Host.getHost(0);
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
DistributedTestUtils.deleteLocatorStateFile(port1);
String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]";
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
addDSProps(props);
final String expected = "java.net.ConnectException";
final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
bgexecLogger.info(addExpected);
boolean exceptionOccurred = true;
try {
DistributedSystem.connect(props);
exceptionOccurred = false;
} catch (DistributionException ex) {
// I guess it can throw this too...
} catch (GemFireConfigException ex) {
String s = ex.getMessage();
assertTrue(s.indexOf("Locator does not exist") >= 0);
} catch (Exception ex) {
// if you see this fail, determine if unexpected exception is expected
// if expected then add in a catch block for it above this catch
org.apache.geode.test.dunit.Assert.fail("Failed with unexpected exception", ex);
} finally {
bgexecLogger.info(removeExpected);
}
if (!exceptionOccurred) {
fail("Should have thrown a GemFireConfigException");
}
}
use of org.apache.geode.LogWriter in project geode by apache.
the class TestFunction method executeFunctionReturningArgs.
public void executeFunctionReturningArgs(FunctionContext context) {
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
LogWriter logger = ds.getLogWriter();
logger.info("Executing executeFunctionReturningArgs in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
if (!hasResult()) {
return;
}
Object[] args = (Object[]) context.getArguments();
if (args != null) {
context.getResultSender().lastResult(args[0]);
} else {
context.getResultSender().lastResult(Boolean.FALSE);
}
}
use of org.apache.geode.LogWriter in project geode by apache.
the class TestFunction method execute1.
public void execute1(FunctionContext context) {
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
LogWriter logger = ds.getLogWriter();
logger.info("Executing execute1 in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
if (!hasResult()) {
return;
}
if (context.getArguments() instanceof Boolean) {
// context.getResultSender().sendResult();
context.getResultSender().lastResult((Serializable) context.getArguments());
} else if (context.getArguments() instanceof String) {
/*
* String key = (String)context.getArguments(); return key;
*/
context.getResultSender().lastResult((Serializable) context.getArguments());
} else if (context.getArguments() instanceof Set) {
Set origKeys = (Set) context.getArguments();
ArrayList vals = new ArrayList();
for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
Object val = i.next();
if (val != null) {
vals.add(val);
}
}
/* return vals; */
context.getResultSender().lastResult(vals);
} else {
/* return Boolean.FALSE; */
context.getResultSender().lastResult(Boolean.FALSE);
}
}
Aggregations