use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class ReconnectDUnitTest method forceDisconnect.
public boolean forceDisconnect(VM vm) throws Exception {
SerializableCallable fd = new SerializableCallable("crash distributed system") {
public Object call() throws Exception {
// since the system will disconnect and attempt to reconnect
// a new system the old reference to DTC.system can cause
// trouble, so we first null it out.
nullSystem();
final DistributedSystem msys = InternalDistributedSystem.getAnyInstance();
final Locator oldLocator = Locator.getLocator();
MembershipManagerHelper.crashDistributedSystem(msys);
if (oldLocator != null) {
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return msys.isReconnecting();
}
public String description() {
return "waiting for locator to start reconnecting: " + oldLocator;
}
};
Wait.waitForCriterion(wc, 10000, 50, true);
}
return true;
}
};
if (vm != null) {
return (Boolean) vm.invoke(fd);
} else {
return (Boolean) fd.call();
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class TestDiskRegion method main4.
/**
* Byte arrays
*/
public static void main4(String[] args) throws Exception {
DistributedSystem system = DistributedSystem.connect(new java.util.Properties());
Cache cache = CacheFactory.create(system);
AttributesFactory factory = new AttributesFactory();
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(2, (ObjectSizer) null, EvictionAction.OVERFLOW_TO_DISK));
LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create());
for (int i = 0; i < 100000; i++) {
System.out.println(i);
region.put(String.valueOf(i), String.valueOf(i).getBytes());
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class TestDiskRegion method main1.
public static void main1(String[] args) throws Exception {
DistributedSystem system = DistributedSystem.connect(new java.util.Properties());
Cache cache = CacheFactory.create(system);
AttributesFactory factory = new AttributesFactory();
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(2, (ObjectSizer) null, EvictionAction.OVERFLOW_TO_DISK));
factory.setCacheListener(new CacheListenerAdapter() {
public void afterUpdate(EntryEvent event) {
System.out.println("UPDATE: " + event.getKey() + " -> (" + event.getOldValue() + " -> " + event.getNewValue() + ")");
}
});
LocalRegion region = (LocalRegion) cache.createRegion("TestDiskRegion", factory.create());
DiskRegion dr = region.getDiskRegion();
DiskRegionStats diskStats = dr.getStats();
LRUStatistics lruStats = getLRUStats(region);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Hit enter to perform action");
for (int i = 0; true; i++) {
br.readLine();
// Thread.sleep(500);
Object key = new Integer(i);
Object value = new byte[200000];
region.put(key, value);
System.out.println(key + " -> " + value + " evictions = " + lruStats.getEvictions() + ", writes = " + diskStats.getWrites());
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class ClassPathLoaderIntegrationTest method testDeployWithExistingDependentJars.
@Test
public void testDeployWithExistingDependentJars() throws Exception {
ClassBuilder classBuilder = new ClassBuilder();
final File parentJarFile = new File(temporaryFolder.getRoot(), "JarDeployerDUnitAParent.v1.jar");
final File usesJarFile = new File(temporaryFolder.getRoot(), "JarDeployerDUnitUses.v1.jar");
final File functionJarFile = new File(temporaryFolder.getRoot(), "JarDeployerDUnitFunction.v1.jar");
// Write out a JAR files.
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("package jddunit.parent;");
stringBuffer.append("public class JarDeployerDUnitParent {");
stringBuffer.append("public String getValueParent() {");
stringBuffer.append("return \"PARENT\";}}");
byte[] jarBytes = classBuilder.createJarFromClassContent("jddunit/parent/JarDeployerDUnitParent", stringBuffer.toString());
FileOutputStream outStream = new FileOutputStream(parentJarFile);
outStream.write(jarBytes);
outStream.close();
stringBuffer = new StringBuffer();
stringBuffer.append("package jddunit.uses;");
stringBuffer.append("public class JarDeployerDUnitUses {");
stringBuffer.append("public String getValueUses() {");
stringBuffer.append("return \"USES\";}}");
jarBytes = classBuilder.createJarFromClassContent("jddunit/uses/JarDeployerDUnitUses", stringBuffer.toString());
outStream = new FileOutputStream(usesJarFile);
outStream.write(jarBytes);
outStream.close();
stringBuffer = new StringBuffer();
stringBuffer.append("package jddunit.function;");
stringBuffer.append("import jddunit.parent.JarDeployerDUnitParent;");
stringBuffer.append("import jddunit.uses.JarDeployerDUnitUses;");
stringBuffer.append("import org.apache.geode.cache.execute.Function;");
stringBuffer.append("import org.apache.geode.cache.execute.FunctionContext;");
stringBuffer.append("public class JarDeployerDUnitFunction extends JarDeployerDUnitParent implements Function {");
stringBuffer.append("private JarDeployerDUnitUses uses = new JarDeployerDUnitUses();");
stringBuffer.append("public boolean hasResult() {return true;}");
stringBuffer.append("public void execute(FunctionContext context) {context.getResultSender().lastResult(getValueParent() + \":\" + uses.getValueUses());}");
stringBuffer.append("public String getId() {return \"JarDeployerDUnitFunction\";}");
stringBuffer.append("public boolean optimizeForWrite() {return false;}");
stringBuffer.append("public boolean isHA() {return false;}}");
ClassBuilder functionClassBuilder = new ClassBuilder();
functionClassBuilder.addToClassPath(parentJarFile.getAbsolutePath());
functionClassBuilder.addToClassPath(usesJarFile.getAbsolutePath());
jarBytes = functionClassBuilder.createJarFromClassContent("jddunit/function/JarDeployerDUnitFunction", stringBuffer.toString());
outStream = new FileOutputStream(functionJarFile);
outStream.write(jarBytes);
outStream.close();
ServerStarterRule serverStarterRule = new ServerStarterRule(temporaryFolder.getRoot());
serverStarterRule.startServer();
GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance();
DistributedSystem distributedSystem = gemFireCache.getDistributedSystem();
Execution execution = FunctionService.onMember(distributedSystem.getDistributedMember());
ResultCollector resultCollector = execution.execute("JarDeployerDUnitFunction");
@SuppressWarnings("unchecked") List<String> result = (List<String>) resultCollector.getResult();
assertEquals("PARENT:USES", result.get(0));
serverStarterRule.after();
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class Bug37241DUnitTest method createCache.
private void createCache(Properties props) throws Exception {
DistributedSystem ds = getSystem(props);
ds.disconnect();
ds = getSystem(props);
assertNotNull(ds);
cache = CacheFactory.create(ds);
assertNotNull(cache);
}
Aggregations