Search in sources :

Example 1 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class RegionTestCase method remoteTestPostSnapshot.

public void remoteTestPostSnapshot(String name, boolean isController, boolean isRoot) throws CacheException {
    assertTrue(preSnapshotRegion.isDestroyed());
    try {
        preSnapshotRegion.get("0");
        fail("Should have thrown a RegionReinitializedException");
    } catch (RegionReinitializedException e) {
    // pass
    }
    LogWriter log = getCache().getLogger();
    // get new reference to region
    Region postSnapshotRegion = isRoot ? getRootRegion(name) : getRootRegion().getSubregion(name);
    assertNotNull("Could not get reference to reinitialized region", postSnapshotRegion);
    boolean expectData = isController || postSnapshotRegion.getAttributes().getMirrorType().isMirrored() || postSnapshotRegion.getAttributes().getDataPolicy().isPreloaded();
    log.info("region has " + postSnapshotRegion.keySet().size() + " entries");
    assertEquals(expectData ? MAX_KEYS : 0, postSnapshotRegion.keySet().size());
    // gets the data either locally or by netSearch
    assertEquals(new Integer(3), postSnapshotRegion.get("3"));
    // bug 33311 coverage
    if (expectData) {
        assertFalse(postSnapshotRegion.containsValueForKey("9"));
        assertTrue(postSnapshotRegion.containsKey("9"));
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException)

Example 2 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class RegionTestCase method testRootSnapshot.

@Test
public void testRootSnapshot() throws IOException, CacheException, ClassNotFoundException {
    final String name = this.getUniqueName();
    // create region in controller
    preSnapshotRegion = createRootRegion(name, getRegionAttributes());
    // create region in other VMs if distributed
    boolean isDistributed = getRegionAttributes().getScope().isDistributed();
    if (isDistributed) {
        Invoke.invokeInEveryVM(new CacheSerializableRunnable("create presnapshot region") {

            public void run2() throws CacheException {
                preSnapshotRegion = createRootRegion(name, getRegionAttributes());
            }
        });
    }
    // add data to region in controller
    for (int i = 0; i < MAX_KEYS; i++) {
        if (i == MAX_KEYS - 1) {
            // bug 33311 coverage
            preSnapshotRegion.create(String.valueOf(i), null);
        } else {
            preSnapshotRegion.create(String.valueOf(i), new Integer(i));
        }
    }
    // save snapshot
    File file = new File(name + ".snap");
    OutputStream out = new FileOutputStream(file);
    try {
        preSnapshotRegion.saveSnapshot(out);
        assertEquals(new Integer(5), preSnapshotRegion.get("5"));
        // destroy all data
        for (int i = 0; i < MAX_KEYS; i++) {
            preSnapshotRegion.destroy(String.valueOf(i));
        }
        assertTrue(preSnapshotRegion.keySet().size() == 0);
        LogWriter log = getCache().getLogger();
        log.info("before loadSnapshot");
        // DebuggerSupport.waitForJavaDebugger(getLogWriter());
        InputStream in = new FileInputStream(file);
        preSnapshotRegion.loadSnapshot(in);
        log.info("after loadSnapshot");
        // test postSnapshot behavior in controller
        log.info("before controller remoteTestPostSnapshot");
        remoteTestPostSnapshot(name, true, true);
        log.info("after controller remoteTestPostSnapshot");
        // test postSnapshot behavior in other VMs if distributed
        if (isDistributed) {
            log.info("before distributed remoteTestPostSnapshot");
            Invoke.invokeInEveryVM(new CacheSerializableRunnable("postSnapshot") {

                public void run2() throws CacheException {
                    RegionTestCase.this.remoteTestPostSnapshot(name, false, true);
                }
            });
            log.info("after distributed remoteTestPostSnapshot");
        }
    } finally {
        file.delete();
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) LogWriter(org.apache.geode.LogWriter) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 3 with LogWriter

use of org.apache.geode.LogWriter 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 4 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class TestFunction method executeFunctionReturningArgs.

public void executeFunctionReturningArgs(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.info("Executing executeFunctionReturningArgs in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (!hasResult()) {
        return;
    }
    Object[] args = (Object[]) context.getArguments();
    if (args != null) {
        context.getResultSender().lastResult(args[0]);
    } else {
        context.getResultSender().lastResult(Boolean.FALSE);
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 5 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class TestFunction method execute1.

public void execute1(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.info("Executing execute1 in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (!hasResult()) {
        return;
    }
    if (context.getArguments() instanceof Boolean) {
        // context.getResultSender().sendResult();
        context.getResultSender().lastResult((Serializable) context.getArguments());
    } else if (context.getArguments() instanceof String) {
        /*
       * String key = (String)context.getArguments(); return key;
       */
        context.getResultSender().lastResult((Serializable) context.getArguments());
    } else if (context.getArguments() instanceof Set) {
        Set origKeys = (Set) context.getArguments();
        ArrayList vals = new ArrayList();
        for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
            Object val = i.next();
            if (val != null) {
                vals.add(val);
            }
        }
        /* return vals; */
        context.getResultSender().lastResult(vals);
    } else {
        /* return Boolean.FALSE; */
        context.getResultSender().lastResult(Boolean.FALSE);
    }
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) LogWriter(org.apache.geode.LogWriter) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Aggregations

LogWriter (org.apache.geode.LogWriter)87 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)18 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)17 Host (org.apache.geode.test.dunit.Host)17 Region (org.apache.geode.cache.Region)15 DistributedSystem (org.apache.geode.distributed.DistributedSystem)15 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)15 VM (org.apache.geode.test.dunit.VM)13 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)12 Iterator (java.util.Iterator)11 Set (java.util.Set)11 Cache (org.apache.geode.cache.Cache)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)9 Properties (java.util.Properties)8 InternalLogWriter (org.apache.geode.internal.logging.InternalLogWriter)8 IOException (java.io.IOException)7 HashSet (java.util.HashSet)7