Search in sources :

Example 1 with TestCacheWriter

use of org.apache.geode.cache30.TestCacheWriter in project geode by apache.

the class ConnectionPoolDUnitTest method testDestroyRegion.

/**
   * Tests that a {@link Region#localDestroyRegion} is not propagated to the server and that a
   * {@link Region#destroyRegion} is. Also makes sure that callback arguments are passed correctly.
   */
@Ignore("TODO")
@Test
public void testDestroyRegion() 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);
    final Object callbackArg = "DESTROY CALLBACK";
    vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            CacheWriter cw = new TestCacheWriter() {

                public void beforeCreate2(EntryEvent event) throws CacheWriterException {
                }

                public void beforeRegionDestroy2(RegionEvent event) throws CacheWriterException {
                    assertEquals(callbackArg, event.getCallbackArgument());
                }
            };
            AttributesFactory factory = getBridgeServerRegionAttributes(null, cw);
            createRegion(name, factory.create());
            // pause(1000);
            try {
                startBridgeServer(0);
            } catch (Exception ex) {
                org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    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, port, -1, true, -1, -1, null);
            createRegion(name, factory.create());
        }
    };
    vm1.invoke(create);
    vm2.invoke(create);
    vm1.invoke(new CacheSerializableRunnable("Local destroy region") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.localDestroyRegion();
            assertNull(getRootRegion().getSubregion(name));
        // close the bridge writer to prevent callbacks on the connections
        // Not necessary since locally destroying the region takes care of this.
        // getPoolClient(region).close();
        }
    });
    vm2.invoke(new CacheSerializableRunnable("No destroy propagate") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            assertNotNull(region);
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Check no server cache writer") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            TestCacheWriter writer = getTestWriter(region);
            writer.wasInvoked();
        }
    });
    vm1.invoke(create);
    vm1.invoke(new CacheSerializableRunnable("Distributed destroy region") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            assertNotNull(region);
            region.destroyRegion(callbackArg);
            assertNull(getRootRegion().getSubregion(name));
        // close the bridge writer to prevent callbacks on the connections
        // Not necessary since locally destroying the region takes care of this.
        // getPoolClient(region).close();
        }
    });
    // Wait for destroys to propagate
    Wait.pause(1000);
    vm2.invoke(new CacheSerializableRunnable("Verify destroy propagate") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            assertNull(region);
        // todo close the bridge writer
        // Not necessary since locally destroying the region takes care of this.
        }
    });
    vm0.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) 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) VM(org.apache.geode.test.dunit.VM) TestCacheWriter(org.apache.geode.cache30.TestCacheWriter) LocalRegion(org.apache.geode.internal.cache.LocalRegion) TestCacheWriter(org.apache.geode.cache30.TestCacheWriter) Ignore(org.junit.Ignore) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 2 with TestCacheWriter

use of org.apache.geode.cache30.TestCacheWriter in project geode by apache.

the class ConnectionPoolDUnitTest method test001CallbackArg.

/**
   * Tests that the callback argument is sent to the server
   */
@Test
public void test001CallbackArg() throws CacheException {
    final String name = this.getName();
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final Object createCallbackArg = "CREATE CALLBACK ARG";
    final Object updateCallbackArg = "PUT CALLBACK ARG";
    vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            CacheWriter cw = new TestCacheWriter() {

                public final void beforeUpdate2(EntryEvent event) throws CacheWriterException {
                    Object beca = event.getCallbackArgument();
                    assertEquals(updateCallbackArg, beca);
                }

                public void beforeCreate2(EntryEvent event) throws CacheWriterException {
                    Object beca = event.getCallbackArgument();
                    assertEquals(createCallbackArg, beca);
                }
            };
            AttributesFactory factory = getBridgeServerRegionAttributes(null, cw);
            createRegion(name, factory.create());
            // pause(1000);
            try {
                startBridgeServer(0);
            } catch (Exception ex) {
                org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    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, NetworkUtils.getServerHostName(host), port, -1, true, -1, -1, null);
            createRegion(name, factory.create());
        }
    };
    vm1.invoke(create);
    vm1.invoke(new CacheSerializableRunnable("Add entries") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                region.create(new Integer(i), "old" + i, createCallbackArg);
            }
            for (int i = 0; i < 10; i++) {
                region.put(new Integer(i), "new" + i, updateCallbackArg);
            }
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Check cache writer") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            TestCacheWriter writer = getTestWriter(region);
            assertTrue(writer.wasInvoked());
        }
    });
    SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.localDestroyRegion();
        }
    };
    vm1.invoke(close);
    vm0.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) 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) VM(org.apache.geode.test.dunit.VM) TestCacheWriter(org.apache.geode.cache30.TestCacheWriter) LocalRegion(org.apache.geode.internal.cache.LocalRegion) TestCacheWriter(org.apache.geode.cache30.TestCacheWriter) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 3 with TestCacheWriter

use of org.apache.geode.cache30.TestCacheWriter in project geode by apache.

the class ConnectionPoolDUnitTest method test025Destroy.

/**
   * Tests that a {@link Region#localDestroy} is not propagated to the server and that a
   * {@link Region#destroy} is. Also makes sure that callback arguments are passed correctly.
   */
@Test
public void test025Destroy() 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);
    final Object callbackArg = "DESTROY CALLBACK";
    vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            CacheWriter cw = new TestCacheWriter() {

                public void beforeCreate2(EntryEvent event) throws CacheWriterException {
                }

                public void beforeDestroy2(EntryEvent event) throws CacheWriterException {
                    Object beca = event.getCallbackArgument();
                    assertEquals(callbackArg, beca);
                }
            };
            AttributesFactory factory = getBridgeServerRegionAttributes(null, cw);
            createRegion(name, factory.create());
            try {
                startBridgeServer(0);
            } catch (Exception ex) {
                org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    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, port, -1, true, -1, -1, null);
            Region rgn = createRegion(name, factory.create());
            rgn.registerInterestRegex(".*", false, false);
        }
    };
    vm1.invoke(create);
    vm1.invoke(new CacheSerializableRunnable("Populate region") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                region.put(new Integer(i), String.valueOf(i));
            }
        }
    });
    vm2.invoke(create);
    vm2.invoke(new CacheSerializableRunnable("Load region") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                assertEquals(String.valueOf(i), region.get(new Integer(i)));
            }
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Local destroy") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                region.localDestroy(new Integer(i));
            }
        }
    });
    vm2.invoke(new CacheSerializableRunnable("No destroy propagate") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                assertEquals(String.valueOf(i), region.get(new Integer(i)));
            }
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Fetch from server") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                assertEquals(String.valueOf(i), region.get(new Integer(i)));
            }
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Check no server cache writer") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            TestCacheWriter writer = getTestWriter(region);
            writer.wasInvoked();
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Distributed destroy") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                region.destroy(new Integer(i), callbackArg);
            }
        }
    });
    // Wait for destroys to propagate
    Wait.pause(1000);
    vm1.invoke(new CacheSerializableRunnable("Attempt get from server") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                assertNull(region.getEntry(new Integer(i)));
            }
        }
    });
    vm2.invoke(new CacheSerializableRunnable("Validate destroy propagate") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                assertNull(region.getEntry(new Integer(i)));
            }
        }
    });
    SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.localDestroyRegion();
        }
    };
    vm1.invoke(close);
    vm2.invoke(close);
    vm0.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) 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) VM(org.apache.geode.test.dunit.VM) TestCacheWriter(org.apache.geode.cache30.TestCacheWriter) LocalRegion(org.apache.geode.internal.cache.LocalRegion) TestCacheWriter(org.apache.geode.cache30.TestCacheWriter) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 4 with TestCacheWriter

use of org.apache.geode.cache30.TestCacheWriter in project geode by apache.

the class ConnectionPoolDUnitTest method test002CallbackArg2.

/**
   * Tests that consecutive puts have the callback assigned appropriately.
   */
@Test
public void test002CallbackArg2() throws CacheException {
    final String name = this.getName();
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final Object createCallbackArg = "CREATE CALLBACK ARG";
    // final Object updateCallbackArg = "PUT CALLBACK ARG";
    vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            CacheWriter cw = new TestCacheWriter() {

                public void beforeCreate2(EntryEvent event) throws CacheWriterException {
                    Integer key = (Integer) event.getKey();
                    if (key.intValue() % 2 == 0) {
                        Object beca = event.getCallbackArgument();
                        assertEquals(createCallbackArg, beca);
                    } else {
                        Object beca = event.getCallbackArgument();
                        assertNull(beca);
                    }
                }
            };
            AttributesFactory factory = getBridgeServerRegionAttributes(null, cw);
            createRegion(name, factory.create());
            // pause(1000);
            try {
                startBridgeServer(0);
            } catch (Exception ex) {
                org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    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, port, -1, true, -1, -1, null);
            createRegion(name, factory.create());
        }
    };
    vm1.invoke(create);
    vm1.invoke(new CacheSerializableRunnable("Add entries") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < 10; i++) {
                if (i % 2 == 0) {
                    region.create(new Integer(i), "old" + i, createCallbackArg);
                } else {
                    region.create(new Integer(i), "old" + i);
                }
            }
        }
    });
    SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.localDestroyRegion();
        }
    };
    vm1.invoke(close);
    vm0.invoke(new CacheSerializableRunnable("Check cache writer") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            TestCacheWriter writer = getTestWriter(region);
            assertTrue(writer.wasInvoked());
        }
    });
    vm0.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) 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) VM(org.apache.geode.test.dunit.VM) TestCacheWriter(org.apache.geode.cache30.TestCacheWriter) LocalRegion(org.apache.geode.internal.cache.LocalRegion) TestCacheWriter(org.apache.geode.cache30.TestCacheWriter) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)4 CancelException (org.apache.geode.CancelException)4 NoAvailableServersException (org.apache.geode.cache.client.NoAvailableServersException)4 Endpoint (org.apache.geode.cache.client.internal.Endpoint)4 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)4 TestCacheWriter (org.apache.geode.cache30.TestCacheWriter)4 LocalRegion (org.apache.geode.internal.cache.LocalRegion)4 Host (org.apache.geode.test.dunit.Host)4 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)4 VM (org.apache.geode.test.dunit.VM)4 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 Test (org.junit.Test)4 Ignore (org.junit.Ignore)1