Search in sources :

Example 36 with DistributedSystem

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();
    }
}
Also used : ServerLocator(org.apache.geode.distributed.internal.ServerLocator) Locator(org.apache.geode.distributed.Locator) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 37 with DistributedSystem

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());
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) ObjectSizer(org.apache.geode.cache.util.ObjectSizer) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache)

Example 38 with DistributedSystem

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());
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) DiskRegionStats(org.apache.geode.internal.cache.DiskRegionStats) ObjectSizer(org.apache.geode.cache.util.ObjectSizer) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedSystem(org.apache.geode.distributed.DistributedSystem) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskRegion(org.apache.geode.internal.cache.DiskRegion) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) BufferedReader(java.io.BufferedReader) Cache(org.apache.geode.cache.Cache)

Example 39 with DistributedSystem

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();
}
Also used : DistributedSystem(org.apache.geode.distributed.DistributedSystem) ServerStarterRule(org.apache.geode.test.dunit.rules.ServerStarterRule) Execution(org.apache.geode.cache.execute.Execution) FileOutputStream(java.io.FileOutputStream) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) List(java.util.List) File(java.io.File) ResultCollector(org.apache.geode.cache.execute.ResultCollector) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 40 with DistributedSystem

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);
}
Also used : DistributedSystem(org.apache.geode.distributed.DistributedSystem)

Aggregations

DistributedSystem (org.apache.geode.distributed.DistributedSystem)250 Properties (java.util.Properties)102 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)65 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)61 Test (org.junit.Test)59 Cache (org.apache.geode.cache.Cache)55 AttributesFactory (org.apache.geode.cache.AttributesFactory)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)30 Region (org.apache.geode.cache.Region)24 IOException (java.io.IOException)20 CacheServer (org.apache.geode.cache.server.CacheServer)20 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)20 InternalCache (org.apache.geode.internal.cache.InternalCache)16 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 ArrayList (java.util.ArrayList)15 LogWriter (org.apache.geode.LogWriter)15 DistributedMember (org.apache.geode.distributed.DistributedMember)15 LocalRegion (org.apache.geode.internal.cache.LocalRegion)15 RegionAttributes (org.apache.geode.cache.RegionAttributes)14 Pool (org.apache.geode.cache.client.Pool)14