Search in sources :

Example 1 with LocalLogWriter

use of org.apache.geode.internal.logging.LocalLogWriter 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");
    }
}
Also used : LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LogWriter(org.apache.geode.LogWriter) GemFireConfigException(org.apache.geode.GemFireConfigException) Host(org.apache.geode.test.dunit.Host) DistributionException(org.apache.geode.distributed.internal.DistributionException) Properties(java.util.Properties) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) DistributionException(org.apache.geode.distributed.internal.DistributionException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 2 with LocalLogWriter

use of org.apache.geode.internal.logging.LocalLogWriter in project geode by apache.

the class QueueManagerJUnitTest method setUp.

@Before
public void setUp() {
    this.logger = new LocalLogWriter(InternalLogWriter.FINEST_LEVEL, System.out);
    Properties properties = new Properties();
    properties.put(MCAST_PORT, "0");
    properties.put(LOCATORS, "");
    ds = DistributedSystem.connect(properties);
    stats = new PoolStats(ds, "QueueManagerJUnitTest");
    pool = new DummyPool();
    endpoints = new EndpointManagerImpl("pool", ds, ds.getCancelCriterion(), pool.getStats());
    source = new DummySource();
    factory = new DummyFactory();
    background = Executors.newSingleThreadScheduledExecutor();
    final String addExpectedPEM = "<ExpectedException action=add>" + expectedPrimaryErrorMsg + "</ExpectedException>";
    final String addExpectedREM = "<ExpectedException action=add>" + expectedRedundantErrorMsg + "</ExpectedException>";
    ds.getLogWriter().info(addExpectedPEM);
    ds.getLogWriter().info(addExpectedREM);
}
Also used : LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) PoolStats(org.apache.geode.internal.cache.PoolStats) Before(org.junit.Before)

Example 3 with LocalLogWriter

use of org.apache.geode.internal.logging.LocalLogWriter in project geode by apache.

the class LocatorLoadBalancingDUnitTest method checkLocatorLoad.

public void checkLocatorLoad(final Map expected) {
    List locators = Locator.getLocators();
    Assert.assertEquals(1, locators.size());
    InternalLocator locator = (InternalLocator) locators.get(0);
    final ServerLocator sl = locator.getServerLocatorAdvisee();
    InternalLogWriter log = new LocalLogWriter(InternalLogWriter.FINEST_LEVEL, System.out);
    sl.getDistributionAdvisor().dumpProfiles("PROFILES= ");
    Awaitility.await().pollDelay(100, TimeUnit.MILLISECONDS).pollInterval(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> expected.equals(sl.getLoadMap()));
}
Also used : InternalLocator(org.apache.geode.distributed.internal.InternalLocator) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) List(java.util.List) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) ServerLocator(org.apache.geode.distributed.internal.ServerLocator)

Example 4 with LocalLogWriter

use of org.apache.geode.internal.logging.LocalLogWriter in project geode by apache.

the class ConnectionManagerJUnitTest method setUp.

@Before
public void setUp() {
    this.logger = new LocalLogWriter(InternalLogWriter.FINEST_LEVEL, System.out);
    factory = new DummyFactory();
    Properties properties = new Properties();
    properties.put(MCAST_PORT, "0");
    properties.put(LOCATORS, "");
    ds = DistributedSystem.connect(properties);
    background = Executors.newSingleThreadScheduledExecutor();
    poolStats = new PoolStats(ds, "connectionManagerJUnitTest");
    endpointManager = new EndpointManagerImpl("pool", ds, ds.getCancelCriterion(), poolStats);
    cancelCriterion = new CancelCriterion() {

        public String cancelInProgress() {
            return null;
        }

        public RuntimeException generateCancelledException(Throwable e) {
            return null;
        }
    };
}
Also used : CancelCriterion(org.apache.geode.CancelCriterion) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) Properties(java.util.Properties) PoolStats(org.apache.geode.internal.cache.PoolStats) Before(org.junit.Before)

Example 5 with LocalLogWriter

use of org.apache.geode.internal.logging.LocalLogWriter in project geode by apache.

the class ConnectionPoolDUnitTest method basicTestBridgeServerFailover.

private void basicTestBridgeServerFailover(final int cnxCount) throws CacheException {
    final String name = this.getName();
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    // Create two bridge servers
    SerializableRunnable createCacheServer = new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            AttributesFactory factory = getBridgeServerRegionAttributes(null, null);
            createRegion(name, factory.create());
            // pause(1000);
            try {
                startBridgeServer(0);
            } catch (Exception ex) {
                org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
            }
        }
    };
    vm0.invoke(createCacheServer);
    vm1.invoke(createCacheServer);
    final int port0 = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    final int port1 = vm1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    // final String host1 = getServerHostName(vm1.getHost());
    // Create one bridge client in this VM
    SerializableRunnable create = new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            getLonerSystem();
            getCache();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            factory.setConcurrencyChecksEnabled(false);
            ClientServerTestCase.configureConnectionPool(factory, host0, port0, port1, true, -1, cnxCount, null, 100);
            Region region = createRegion(name, factory.create());
            // force connections to form
            region.put("keyInit", new Integer(0));
            region.put("keyInit2", new Integer(0));
        }
    };
    vm2.invoke(create);
    // Launch async thread that puts objects into cache. This thread will execute until
    // the test has ended (which is why the RegionDestroyedException and CacheClosedException
    // are caught and ignored. If any other exception occurs, the test will fail. See
    // the putAI.exceptionOccurred() assertion below.
    AsyncInvocation putAI = vm2.invokeAsync(new CacheSerializableRunnable("Put objects") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            try {
                for (int i = 0; i < 100000; i++) {
                    region.put("keyAI", new Integer(i));
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ie) {
                        fail("interrupted");
                    }
                }
            } catch (NoAvailableServersException ignore) {
            /* ignore */
            } catch (RegionDestroyedException e) {
            // will be thrown when the test ends
            /* ignore */
            } catch (CancelException e) {
            // will be thrown when the test ends
            /* ignore */
            }
        }
    });
    SerializableRunnable verify1Server = new CacheSerializableRunnable("verify1Server") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            PoolImpl pool = getPool(region);
            verifyServerCount(pool, 1);
        }
    };
    SerializableRunnable verify2Servers = new CacheSerializableRunnable("verify2Servers") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            PoolImpl pool = getPool(region);
            verifyServerCount(pool, 2);
        }
    };
    vm2.invoke(verify2Servers);
    SerializableRunnable stopCacheServer = new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    };
    final String expected = "java.io.IOException";
    final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
    final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
    vm2.invoke(new SerializableRunnable() {

        public void run() {
            LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
            bgexecLogger.info(addExpected);
        }
    });
    try {
        // make sure we removeExpected
        // Bounce the non-current server (I know that VM1 contains the non-current server
        // because ...
        vm1.invoke(stopCacheServer);
        vm2.invoke(verify1Server);
        final int restartPort = port1;
        vm1.invoke(new SerializableRunnable("Restart CacheServer") {

            public void run() {
                try {
                    Region region = getRootRegion().getSubregion(name);
                    assertNotNull(region);
                    startBridgeServer(restartPort);
                } catch (Exception e) {
                    getSystem().getLogWriter().fine(new Exception(e));
                    org.apache.geode.test.dunit.Assert.fail("Failed to start CacheServer", e);
                }
            }
        });
        // Pause long enough for the monitor to realize the server has been bounced
        // and reconnect to it.
        vm2.invoke(verify2Servers);
    } finally {
        vm2.invoke(new SerializableRunnable() {

            public void run() {
                LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
                bgexecLogger.info(removeExpected);
            }
        });
    }
    // Stop the other cache server
    vm0.invoke(stopCacheServer);
    // Run awhile
    vm2.invoke(verify1Server);
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info(// FIXME
    "FIXME: this thread does not terminate");
    // // Verify that no exception has occurred in the putter thread
    // join(putAI, 5 * 60 * 1000, getLogWriter());
    // //assertTrue("Exception occurred while invoking " + putAI, !putAI.exceptionOccurred());
    // if (putAI.exceptionOccurred()) {
    // fail("While putting entries: ", putAI.getException());
    // }
    // Close Pool
    vm2.invoke(new CacheSerializableRunnable("Close Pool") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.localDestroyRegion();
        }
    });
    // Stop the last cache server
    vm1.invoke(stopCacheServer);
}
Also used : NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) Endpoint(org.apache.geode.cache.client.internal.Endpoint) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LogWriter(org.apache.geode.LogWriter) VM(org.apache.geode.test.dunit.VM) LocalRegion(org.apache.geode.internal.cache.LocalRegion) CancelException(org.apache.geode.CancelException)

Aggregations

LocalLogWriter (org.apache.geode.internal.logging.LocalLogWriter)10 InternalLogWriter (org.apache.geode.internal.logging.InternalLogWriter)7 Properties (java.util.Properties)6 LogWriter (org.apache.geode.LogWriter)6 Host (org.apache.geode.test.dunit.Host)6 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)5 VM (org.apache.geode.test.dunit.VM)5 IOException (java.io.IOException)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)3 Before (org.junit.Before)3 Test (org.junit.Test)3 CancelCriterion (org.apache.geode.CancelCriterion)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 Region (org.apache.geode.cache.Region)2 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)2