use of org.apache.geode.internal.cache.GemFireCacheImpl 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.internal.cache.GemFireCacheImpl in project geode by apache.
the class Bug49856JUnitTest method testNoGFThreadsRunningPostCacheClose.
@Test
public void testNoGFThreadsRunningPostCacheClose() throws Exception {
ClientCacheFactory ccf = new ClientCacheFactory();
GemFireCacheImpl cache = (GemFireCacheImpl) ccf.create();
SystemFailure.getFailure();
Thread.sleep(5000);
// Assert the threads have been started.
checkThreads(true);
cache.close();
Thread.sleep(5000);
// Assert the threads have been terminated.
checkThreads(false);
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testCompactFromAdmin.
/**
* Tests to make sure that we stop waiting for a member that we revoke.
*
* @throws Exception
*/
@Test
public void testCompactFromAdmin() throws Exception {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
createPersistentRegionWithoutCompaction(vm0);
createPersistentRegionWithoutCompaction(vm1);
vm1.invoke(new SerializableRunnable("Create some data") {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 1024; i++) {
region.put(i, new byte[1024]);
}
for (int i = 2; i < 1024; i++) {
assertTrue(region.destroy(i) != null);
}
DiskStore store = cache.findDiskStore(REGION_NAME);
store.forceRoll();
}
});
// vm1.invoke(new SerializableRunnable("compact") {
// public void run() {
// Cache cache = getCache();
// DiskStore ds = cache.findDiskStore(REGION_NAME);
// assertTrue(ds.forceCompaction());
// }
// });
//
// vm0.invoke(new SerializableRunnable("compact") {
// public void run() {
// Cache cache = getCache();
// DiskStore ds = cache.findDiskStore(REGION_NAME);
// assertTrue(ds.forceCompaction());
// }
// });
vm2.invoke(new SerializableRunnable("Compact") {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
DistributedSystemConfig config;
AdminDistributedSystem adminDS = null;
try {
config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
adminDS.connect();
Map<DistributedMember, Set<PersistentID>> missingIds = adminDS.compactAllDiskStores();
assertEquals(2, missingIds.size());
for (Set<PersistentID> value : missingIds.values()) {
assertEquals(1, value.size());
}
} catch (AdminException e) {
throw new RuntimeException(e);
} finally {
if (adminDS != null) {
adminDS.disconnect();
}
}
}
});
SerializableRunnable compactVM = new SerializableRunnable("compact") {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore(REGION_NAME);
assertFalse(ds.forceCompaction());
}
};
vm0.invoke(compactVM);
vm1.invoke(compactVM);
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class RollingUpgrade2DUnitTest method createPersistentReplicateRegion.
public static void createPersistentReplicateRegion(GemFireCache cache, String regionName, File diskStore) throws Exception {
DiskStore store = cache.findDiskStore("store");
if (store == null) {
DiskStoreFactory factory = cache.createDiskStoreFactory();
factory.setMaxOplogSize(1L);
factory.setDiskDirs(new File[] { diskStore.getAbsoluteFile() });
factory.create("store");
}
RegionFactory rf = ((GemFireCacheImpl) cache).createRegionFactory();
rf.setDiskStoreName("store");
rf.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
rf.create(regionName);
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class UnregisterInterestDUnitTest method createCacheAndStartServer.
public static Integer createCacheAndStartServer() throws Exception {
DistributedSystem ds = new UnregisterInterestDUnitTest().getSystem();
ds.disconnect();
Properties props = new Properties();
props.setProperty(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
CacheFactory cf = new CacheFactory(props);
cache = cf.create();
RegionFactory rf = ((GemFireCacheImpl) cache).createRegionFactory(RegionShortcut.REPLICATE);
rf.create(regionname);
CacheServer server = ((GemFireCacheImpl) cache).addCacheServer();
server.setPort(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
server.start();
return server.getPort();
}
Aggregations