Search in sources :

Example 81 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class GemfireDataCommandsDUnitTest method testPutJsonKeys.

// GEODE-1430
@Category(FlakyTest.class)
@Test
public void testPutJsonKeys() {
    final String keyPrefix = "testKey";
    setupForGetPutRemoveLocateEntry("testPutJsonKeys");
    final VM vm1 = Host.getHost(0).getVM(1);
    final VM vm2 = Host.getHost(0).getVM(2);
    for (int i = 0; i < COUNT; i++) {
        String command = "put";
        String keyString = keyPrefix + i;
        String population = "" + i * 100;
        String area = "" + i * (100.4365);
        String keyJson = keyTemplate.replaceAll("\\?", keyString);
        String valueJson = valueTemplate.replaceAll("\\?1", population);
        valueJson = valueJson.replaceAll("\\?2", area);
        valueJson = valueJson.replaceAll("\\?", keyString);
        getLogWriter().info("Putting key with json key : " + keyJson);
        getLogWriter().info("Putting key with json valye : " + valueJson);
        command = command + " " + "--key=" + keyJson + " --value=" + valueJson + " --region=" + DATA_REGION_NAME_PATH;
        command = command + " --key-class=" + Key1.class.getCanonicalName() + " --value-class=" + Value2.class.getCanonicalName();
        CommandResult cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        validateResult(cmdResult, true);
    }
    // Bug #51175
    for (int i = COUNT; i < COUNT + 5; i++) {
        String command = "put";
        String keyString = keyPrefix + i;
        String id = "" + i * 100;
        String make = "" + i * (100.4365);
        String model = "" + i * (100.4365);
        String list = "['red','white','blue']";
        String set = "['red','white','blue']";
        String map = "{'power':'90hp'}";
        String keyJson = keyTemplate.replaceAll("\\?", keyString);
        String valueJson = carTemplate.replaceAll("\\?make", make);
        valueJson = valueJson.replaceAll("\\?model", model);
        valueJson = valueJson.replaceAll("\\?list", list);
        valueJson = valueJson.replaceAll("\\?set", set);
        valueJson = valueJson.replaceAll("\\?map", map);
        getLogWriter().info("Putting key with json key : " + keyJson);
        getLogWriter().info("Putting key with json valye : " + valueJson);
        command = command + " " + "--key=" + keyJson + " --value=" + valueJson + " --region=" + DATA_REGION_NAME_PATH;
        command = command + " --key-class=" + Key1.class.getCanonicalName() + " --value-class=" + Car.class.getCanonicalName();
        CommandResult cmdResult = executeCommand(command);
        printCommandOutput(cmdResult);
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        validateResult(cmdResult, true);
    }
    SerializableRunnable checkPutKeys = new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(DATA_REGION_NAME_PATH);
            assertNotNull(region);
            for (int i = 0; i < COUNT + 5; i++) {
                String keyString = keyPrefix + i;
                Key1 key = new Key1();
                key.setId(keyString);
                key.setName("name" + keyString);
                assertEquals(true, region.containsKey(key));
                // Bug #51175
                if (i >= COUNT) {
                    Car car = (Car) region.get(key);
                    assertNotNull(car.getAttributes());
                    assertNotNull(car.getAttributeSet());
                    assertNotNull(car.getColors());
                }
            }
        }
    };
    vm1.invoke(checkPutKeys);
    vm2.invoke(checkPutKeys);
    doBugCheck50449();
}
Also used : Key1(org.apache.geode.management.internal.cli.dto.Key1) Car(org.apache.geode.management.internal.cli.dto.Car) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Region(org.apache.geode.cache.Region) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 82 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class FunctionCommandsDUnitTest method testExecuteFunctionOnGroups.

// GEODE-1563: JMX RMI (java.rmi.NoSuchObjectException: no such object
@Category(FlakyTest.class)
// in table)
@Test
public void testExecuteFunctionOnGroups() {
    Properties localProps = new Properties();
    localProps.setProperty(NAME, "Manager");
    localProps.setProperty(GROUPS, "Group0");
    setUpJmxManagerOnVm0ThenConnect(localProps);
    Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
    FunctionService.registerFunction(function);
    VM vm1 = Host.getHost(0).getVM(1);
    VM vm2 = Host.getHost(0).getVM(2);
    String vm1id = (String) vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Properties localProps = new Properties();
            localProps.setProperty(GROUPS, "Group1");
            getSystem(localProps);
            Cache cache = getCache();
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
            FunctionService.registerFunction(function);
            return cache.getDistributedSystem().getDistributedMember().getId();
        }
    });
    String vm2id = (String) vm2.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Properties localProps = new Properties();
            localProps.setProperty(GROUPS, "Group2");
            getSystem(localProps);
            Cache cache = getCache();
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
            FunctionService.registerFunction(function);
            return cache.getDistributedSystem().getDistributedMember().getId();
        }
    });
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        public void run() {
            RegionFactory<Integer, Integer> dataRegionFactory = getCache().createRegionFactory(RegionShortcut.REPLICATE);
            Region region = dataRegionFactory.create(REGION_NAME);
            Function function = new TestFunction(true, TestFunction.TEST_FUNCTION1);
            assertNotNull(region);
            FunctionService.registerFunction(function);
        }
    });
    String command = "execute function --id=" + TestFunction.TEST_FUNCTION1 + " --groups=Group1,Group2";
    getLogWriter().info("testExecuteFunctionOnGroups command=" + command);
    CommandResult cmdResult = executeCommand(command);
    getLogWriter().info("testExecuteFunctionOnGroups cmdResult=" + cmdResult);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    TabularResultData resultData = (TabularResultData) cmdResult.getResultData();
    List<String> members = resultData.retrieveAllValues("Member ID/Name");
    getLogWriter().info("testExecuteFunctionOnGroups members=" + members);
    assertTrue(members.size() == 2 && members.contains(vm1id) && members.contains(vm2id));
}
Also used : TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) RegionFactory(org.apache.geode.cache.RegionFactory) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 83 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class TXDistributedDUnitTest method testHighAvailabilityFeatures.

// GEODE-635: eats and logs exceptions, retry loops
@Category(FlakyTest.class)
@Test
public void testHighAvailabilityFeatures() throws Exception {
    IgnoredException.addIgnoredException("DistributedSystemDisconnectedException");
    final String rgnName = getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setEarlyAck(false);
    Region rgn = getCache().createRegion(rgnName, factory.create());
    Invoke.invokeInEveryVM(new SerializableRunnable("testHighAvailabilityFeatures: intial region configuration") {

        public void run() {
            try {
                AttributesFactory factory2 = new AttributesFactory();
                factory2.setScope(Scope.DISTRIBUTED_ACK);
                factory2.setEarlyAck(false);
                factory2.setDataPolicy(DataPolicy.REPLICATE);
                getCache().createRegion(rgnName, factory2.create());
            } catch (CacheException e) {
                Assert.fail("While creating region", e);
            }
        }
    });
    // create entries
    rgn.put("key0", "val0_0");
    rgn.put("key1", "val1_0");
    Host host = Host.getHost(0);
    // This test assumes that there are at least three VMs; the origin and two recipients
    assertTrue(host.getVMCount() >= 3);
    final VM originVM = host.getVM(0);
    // Test that there is no commit after a partial commit message
    // send (only sent to a minority of the recipients)
    originVM.invoke(new SerializableRunnable("Flakey DuringIndividualSend Transaction") {

        public void run() {
            final Region rgn1 = getCache().getRegion(rgnName);
            assertNotNull(rgn1);
            try {
                final CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager();
                final CacheTransactionManager txMgrImpl = txMgr2;
                txMgr2.begin();
                // 1. setup an internal callback on originVM that will call
                // disconnectFromDS() on the 2nd duringIndividualSend
                // call.
                ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).forceLocalBootstrap();
                TXState txState = (TXState) ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).getRealDeal(null, null);
                txState.setDuringIndividualSend(new Runnable() {

                    private int numCalled = 0;

                    public synchronized void run() {
                        ++numCalled;
                        rgn1.getCache().getLogger().info("setDuringIndividualSend Runnable called " + numCalled + " times");
                        if (numCalled > 1) {
                            MembershipManagerHelper.crashDistributedSystem(getSystem());
                        }
                    }
                });
                rgn1.put("key0", "val0_1");
                rgn1.put("key1", "val1_1");
                // 2. commit a transaction in originVM, it will disconnect from the DS
                txMgr2.commit();
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Throwable e) {
                rgn1.getCache().getLogger().warning("Ignoring Exception", e);
            } finally {
                // Allow this VM to re-connect to the DS upon getCache() call
                closeCache();
            }
        }
    });
    // 3. verify on all VMs that the transaction was not committed
    final SerializableRunnable noChangeValidator = new SerializableRunnable("testHighAvailabilityFeatures: validate no change in Region") {

        public void run() {
            Region rgn1 = getCache().getRegion(rgnName);
            if (rgn1 == null) {
                // Expect a null region from originVM
                try {
                    AttributesFactory factory2 = new AttributesFactory();
                    factory2.setScope(Scope.DISTRIBUTED_ACK);
                    factory2.setEarlyAck(false);
                    factory2.setDataPolicy(DataPolicy.REPLICATE);
                    rgn1 = getCache().createRegion(rgnName, factory2.create());
                } catch (CacheException e) {
                    Assert.fail("While creating region", e);
                }
            }
            Region.Entry re = rgn1.getEntry("key0");
            assertNotNull(re);
            assertEquals("val0_0", re.getValue());
            re = rgn1.getEntry("key1");
            assertNotNull(re);
            assertEquals("val1_0", re.getValue());
        }
    };
    Invoke.invokeInEveryVM(noChangeValidator);
    // Test that there is no commit after sending to all recipients
    // but prior to sending the "commit process" message
    originVM.invoke(new SerializableRunnable("Flakey AfterIndividualSend Transaction") {

        public void run() {
            final Region rgn1 = getCache().getRegion(rgnName);
            assertNotNull(rgn1);
            try {
                final CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager();
                final CacheTransactionManager txMgrImpl = txMgr2;
                txMgr2.begin();
                // 1. setup an internal callback on originVM that will call
                // disconnectFromDS() on AfterIndividualSend
                ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).forceLocalBootstrap();
                TXState txState = (TXState) ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).getRealDeal(null, null);
                txState.setAfterIndividualSend(new Runnable() {

                    public synchronized void run() {
                        MembershipManagerHelper.crashDistributedSystem(getSystem());
                    }
                });
                rgn1.put("key0", "val0_2");
                rgn1.put("key1", "val1_2");
                // 2. commit a transaction in originVM, it will disconnect from the DS
                txMgr2.commit();
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Throwable e) {
                rgn1.getCache().getLogger().warning("Ignoring Exception", e);
            } finally {
                // Allow this VM to re-connect to the DS upon getCache() call
                closeCache();
            }
        }
    });
    // 3. verify on all VMs, including the origin, that the transaction was not committed
    Invoke.invokeInEveryVM(noChangeValidator);
    // Test commit success upon a single commit process message received.
    originVM.invoke(new SerializableRunnable("Flakey DuringIndividualCommitProcess Transaction") {

        public void run() {
            final Region rgn1 = getCache().getRegion(rgnName);
            assertNotNull(rgn1);
            try {
                final CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager();
                final CacheTransactionManager txMgrImpl = txMgr2;
                txMgr2.begin();
                ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).forceLocalBootstrap();
                TXState txState = (TXState) ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).getRealDeal(null, null);
                // 1. setup an internal callback on originVM that will call
                // disconnectFromDS() on the 2nd internalDuringIndividualCommitProcess
                // call.
                txState.setDuringIndividualCommitProcess(new Runnable() {

                    private int numCalled = 0;

                    public synchronized void run() {
                        ++numCalled;
                        rgn1.getCache().getLogger().info("setDuringIndividualCommitProcess Runnable called " + numCalled + " times");
                        if (numCalled > 1) {
                            MembershipManagerHelper.crashDistributedSystem(getSystem());
                        }
                    }
                });
                rgn1.put("key0", "val0_3");
                rgn1.put("key1", "val1_3");
                // 2. commit a transaction in originVM, it will disconnect from the DS
                txMgr2.commit();
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Throwable e) {
                rgn1.getCache().getLogger().warning("Ignoring Exception", e);
            } finally {
                // Allow this VM to re-connect to the DS upon getCache() call
                closeCache();
            }
        }
    });
    // 3. verify on all VMs that the transaction was committed (including the orgin, due to GII)
    SerializableRunnable nonSoloChangeValidator1 = new SerializableRunnable("testHighAvailabilityFeatures: validate v1 non-solo Region changes") {

        public void run() {
            Region rgn1 = getCache().getRegion(rgnName);
            if (rgn1 == null) {
                // Expect a null region from originVM
                try {
                    AttributesFactory factory2 = new AttributesFactory();
                    factory2.setScope(Scope.DISTRIBUTED_ACK);
                    factory2.setEarlyAck(false);
                    factory2.setDataPolicy(DataPolicy.REPLICATE);
                    rgn1 = getCache().createRegion(rgnName, factory2.create());
                } catch (CacheException e) {
                    Assert.fail("While creating region", e);
                }
            }
            long giveUp = System.currentTimeMillis() + 10000;
            while (giveUp > System.currentTimeMillis()) {
                try {
                    Region.Entry re = rgn1.getEntry("key0");
                    assertNotNull(re);
                    assertEquals("val0_3", re.getValue());
                    re = rgn1.getEntry("key1");
                    assertNotNull(re);
                    assertEquals("val1_3", re.getValue());
                    break;
                } catch (AssertionError e) {
                    if (giveUp > System.currentTimeMillis()) {
                        throw e;
                    }
                }
            }
        }
    };
    Invoke.invokeInEveryVM(nonSoloChangeValidator1);
    // Verify successful solo region commit after duringIndividualSend
    // (same as afterIndividualSend).
    // Create a region that only exists on the origin and another VM
    final String soloRegionName = getUniqueName() + "_solo";
    SerializableRunnable createSoloRegion = new SerializableRunnable("testHighAvailabilityFeatures: solo region configuration") {

        public void run() {
            try {
                AttributesFactory factory2 = new AttributesFactory();
                factory2.setScope(Scope.DISTRIBUTED_ACK);
                factory2.setEarlyAck(false);
                factory2.setDataPolicy(DataPolicy.REPLICATE);
                Region rgn1 = getCache().createRegion(soloRegionName, factory2.create());
                rgn1.put("soloKey0", "soloVal0_0");
                rgn1.put("soloKey1", "soloVal1_0");
            } catch (CacheException e) {
                Assert.fail("While creating region", e);
            }
        }
    };
    final VM soloRegionVM = host.getVM(1);
    originVM.invoke(createSoloRegion);
    soloRegionVM.invoke(createSoloRegion);
    originVM.invoke(new SerializableRunnable("Flakey solo region DuringIndividualSend Transaction") {

        public void run() {
            final Region soloRgn = getCache().getRegion(soloRegionName);
            assertNotNull(soloRgn);
            try {
                final CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager();
                final CacheTransactionManager txMgrImpl = txMgr2;
                txMgr2.begin();
                // 1. setup an internal callback on originVM that will call
                // disconnectFromDS() on the 2nd duringIndividualSend
                // call.
                ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).forceLocalBootstrap();
                TXState txState = (TXState) ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).getRealDeal(null, null);
                txState.setDuringIndividualSend(new Runnable() {

                    private int numCalled = 0;

                    public synchronized void run() {
                        ++numCalled;
                        soloRgn.getCache().getLogger().info("setDuringIndividualSend Runnable called " + numCalled + " times");
                        if (numCalled > 1) {
                            MembershipManagerHelper.crashDistributedSystem(getSystem());
                        }
                    }
                });
                soloRgn.put("soloKey0", "soloVal0_1");
                soloRgn.put("soloKey1", "soloVal1_1");
                // 2. commit a transaction in originVM, it will disconnect from the DS
                txMgr2.commit();
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Throwable e) {
                soloRgn.getCache().getLogger().warning("Ignoring Exception", e);
            } finally {
                // Allow this VM to re-connect to the DS upon getCache() call
                closeCache();
            }
        }
    });
    // 3. verify on the soloRegionVM that the transaction was committed
    final SerializableRunnable soloRegionCommitValidator1 = new SerializableRunnable("testHighAvailabilityFeatures: validate successful v1 commit in solo Region") {

        public void run() {
            Region soloRgn = getCache().getRegion(soloRegionName);
            if (soloRgn == null) {
                // Expect a null region from originVM
                try {
                    AttributesFactory factory2 = new AttributesFactory();
                    factory2.setScope(Scope.DISTRIBUTED_ACK);
                    factory2.setEarlyAck(false);
                    factory2.setDataPolicy(DataPolicy.REPLICATE);
                    soloRgn = getCache().createRegion(soloRegionName, factory2.create());
                } catch (CacheException e) {
                    Assert.fail("While creating region ", e);
                }
            }
            Region.Entry re = soloRgn.getEntry("soloKey0");
            assertNotNull(re);
            assertEquals("soloVal0_1", re.getValue());
            re = soloRgn.getEntry("soloKey1");
            assertNotNull(re);
            assertEquals("soloVal1_1", re.getValue());
        }
    };
    originVM.invoke(soloRegionCommitValidator1);
    soloRegionVM.invoke(soloRegionCommitValidator1);
    // verify no change in nonSolo region, re-establish region in originVM
    Invoke.invokeInEveryVM(nonSoloChangeValidator1);
    // Verify no commit for failed send (afterIndividualSend) for solo
    // Region combined with non-solo Region
    originVM.invoke(new SerializableRunnable("Flakey mixed (solo+non-solo) region DuringIndividualSend Transaction") {

        public void run() {
            final Region rgn1 = getCache().getRegion(rgnName);
            assertNotNull(rgn1);
            final Region soloRgn = getCache().getRegion(soloRegionName);
            assertNotNull(soloRgn);
            try {
                final CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager();
                final CacheTransactionManager txMgrImpl = txMgr2;
                txMgr2.begin();
                // 1. setup an internal callback on originVM that will call
                // disconnectFromDS() on the afterIndividualSend
                // call.
                ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).forceLocalBootstrap();
                TXState txState = (TXState) ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).getRealDeal(null, null);
                txState.setAfterIndividualSend(new Runnable() {

                    public synchronized void run() {
                        MembershipManagerHelper.crashDistributedSystem(getSystem());
                    }
                });
                rgn1.put("key0", "val0_4");
                rgn1.put("key1", "val1_4");
                soloRgn.put("soloKey0", "soloVal0_2");
                soloRgn.put("soloKey1", "soloVal1_2");
                // 2. commit a transaction in originVM, it will disconnect from the DS
                txMgr2.commit();
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Throwable e) {
                rgn1.getCache().getLogger().warning("Ignoring Exception", e);
            } finally {
                // Allow this VM to re-connect to the DS upon getCache() call
                closeCache();
            }
        }
    });
    // Origin and Solo Region VM should be the same as last validation
    originVM.invoke(soloRegionCommitValidator1);
    soloRegionVM.invoke(soloRegionCommitValidator1);
    Invoke.invokeInEveryVM(nonSoloChangeValidator1);
    // Verify commit after sending a single
    // (duringIndividualCommitProcess) commit process for solo Region
    // combined with non-solo Region
    originVM.invoke(new SerializableRunnable("Flakey mixed (solo+non-solo) region DuringIndividualCommitProcess Transaction") {

        public void run() {
            final Region rgn1 = getCache().getRegion(rgnName);
            assertNotNull(rgn1);
            final Region soloRgn = getCache().getRegion(soloRegionName);
            assertNotNull(soloRgn);
            try {
                final CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager();
                final CacheTransactionManager txMgrImpl = txMgr2;
                txMgr2.begin();
                // 1. setup an internal callback on originVM that will call
                // disconnectFromDS() on the afterIndividualSend
                // call.
                ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).forceLocalBootstrap();
                TXState txState = (TXState) ((TXStateProxyImpl) ((TXManagerImpl) txMgrImpl).getTXState()).getRealDeal(null, null);
                txState.setAfterIndividualSend(new Runnable() {

                    private int numCalled = 0;

                    public synchronized void run() {
                        ++numCalled;
                        rgn1.getCache().getLogger().info("setDuringIndividualCommitProcess Runnable called " + numCalled + " times");
                        if (numCalled > 1) {
                            MembershipManagerHelper.crashDistributedSystem(getSystem());
                        }
                    }
                });
                rgn1.put("key0", "val0_5");
                rgn1.put("key1", "val1_5");
                soloRgn.put("soloKey0", "soloVal0_3");
                soloRgn.put("soloKey1", "soloVal1_3");
                // 2. commit a transaction in originVM, it will disconnect from the DS
                txMgr2.commit();
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Throwable e) {
                rgn1.getCache().getLogger().warning("Ignoring Exception", e);
            } finally {
                // Allow this VM to re-connect to the DS upon getCache() call
                closeCache();
            }
        }
    });
    final SerializableRunnable soloRegionCommitValidator2 = new SerializableRunnable("testHighAvailabilityFeatures: validate successful v2 commit in solo Region") {

        public void run() {
            Region soloRgn = getCache().getRegion(soloRegionName);
            if (soloRgn == null) {
                // Expect a null region from originVM
                try {
                    AttributesFactory factory2 = new AttributesFactory();
                    factory2.setScope(Scope.DISTRIBUTED_ACK);
                    factory2.setEarlyAck(false);
                    factory2.setDataPolicy(DataPolicy.REPLICATE);
                    soloRgn = getCache().createRegion(soloRegionName, factory2.create());
                } catch (CacheException e) {
                    Assert.fail("While creating region ", e);
                }
            }
            Region.Entry re = soloRgn.getEntry("soloKey0");
            assertNotNull(re);
            assertEquals("soloVal0_3", re.getValue());
            re = soloRgn.getEntry("soloKey1");
            assertNotNull(re);
            assertEquals("soloVal1_3", re.getValue());
        }
    };
    originVM.invoke(soloRegionCommitValidator2);
    soloRegionVM.invoke(soloRegionCommitValidator2);
    SerializableRunnable nonSoloChangeValidator2 = new SerializableRunnable("testHighAvailabilityFeatures: validate v2 non-solo Region changes") {

        public void run() {
            Region rgn1 = getCache().getRegion(rgnName);
            if (rgn1 == null) {
                // Expect a null region from originVM
                try {
                    AttributesFactory factory2 = new AttributesFactory();
                    factory2.setScope(Scope.DISTRIBUTED_ACK);
                    factory2.setEarlyAck(false);
                    factory2.setDataPolicy(DataPolicy.REPLICATE);
                    rgn1 = getCache().createRegion(rgnName, factory2.create());
                } catch (CacheException e) {
                    Assert.fail("While creating region", e);
                }
            }
            Region.Entry re = rgn1.getEntry("key0");
            assertNotNull(re);
            assertEquals("val0_5", re.getValue());
            re = rgn1.getEntry("key1");
            assertNotNull(re);
            assertEquals("val1_5", re.getValue());
        }
    };
    Invoke.invokeInEveryVM(nonSoloChangeValidator2);
}
Also used : TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) TXStateProxyImpl(org.apache.geode.internal.cache.TXStateProxyImpl) Host(org.apache.geode.test.dunit.Host) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) TXState(org.apache.geode.internal.cache.TXState) AttributesFactory(org.apache.geode.cache.AttributesFactory) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 84 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class FunctionServiceBase method customCollectorReturnsResultOfSendException.

// GEODE-1981
@Category(FlakyTest.class)
@Test
public void customCollectorReturnsResultOfSendException() {
    ResultCollector rc = getExecution().withCollector(customCollector).execute((context) -> {
        context.getResultSender().sendException(new IllegalStateException());
    });
    final List<Object> result = (List<Object>) rc.getResult();
    assertEquals(numberOfExecutions(), result.size());
    result.stream().forEach(element -> assertEquals(IllegalStateException.class, element.getClass()));
    assertEquals(result, customCollector.getResult());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 85 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class FunctionServiceBase method customCollectorReturnsResultOfSendFunctionException.

// GEODE-1827
@Category(FlakyTest.class)
@Test
public void customCollectorReturnsResultOfSendFunctionException() {
    ResultCollector rc = getExecution().withCollector(customCollector).execute((context) -> {
        context.getResultSender().sendException(new FunctionException());
    });
    final List<Object> result = (List<Object>) rc.getResult();
    assertEquals(numberOfExecutions(), result.size());
    result.stream().forEach(element -> assertEquals(FunctionException.class, element.getClass()));
    assertEquals(result, customCollector.getResult());
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

Category (org.junit.experimental.categories.Category)900 Test (org.junit.Test)856 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)148 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)121 File (java.io.File)102 Instant (org.joda.time.Instant)92 KV (org.apache.beam.sdk.values.KV)86 ArrayList (java.util.ArrayList)84 Row (org.apache.beam.sdk.values.Row)71 Schema (org.apache.beam.sdk.schemas.Schema)65 VM (org.apache.geode.test.dunit.VM)65 QuickTest (com.hazelcast.test.annotation.QuickTest)57 List (java.util.List)57 Matchers.containsString (org.hamcrest.Matchers.containsString)55 InputStream (java.io.InputStream)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)47 FileListView (com.owncloud.android.test.ui.models.FileListView)46 UsesSchema (org.apache.beam.sdk.testing.UsesSchema)43 StringUtils.byteArrayToJsonString (org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString)41 IOException (java.io.IOException)40