Search in sources :

Example 31 with DistributedSystem

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

Example 32 with DistributedSystem

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

Example 33 with DistributedSystem

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;
}
Also used : DistributedSystem(org.apache.geode.distributed.DistributedSystem) SocketException(java.net.SocketException) EOFException(java.io.EOFException) Cache(org.apache.geode.cache.Cache)

Example 34 with DistributedSystem

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();
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 35 with DistributedSystem

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);
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) File(java.io.File)

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