Search in sources :

Example 1 with TXStateProxyImpl

use of org.apache.geode.internal.cache.TXStateProxyImpl in project geode by apache.

the class ServerRegionFunctionExecutor method validateExecution.

@Override
public void validateExecution(Function function, Set targetMembers) {
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && cache.getTxManager().getTXState() != null) {
        TXStateProxyImpl tx = (TXStateProxyImpl) cache.getTxManager().getTXState();
        tx.getRealDeal(null, region);
        tx.incOperationCount();
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) TXStateProxyImpl(org.apache.geode.internal.cache.TXStateProxyImpl)

Example 2 with TXStateProxyImpl

use of org.apache.geode.internal.cache.TXStateProxyImpl in project geode by apache.

the class RegionReliabilityTestCase method testCommitDistributionException.

@Test
public void testCommitDistributionException() throws Exception {
    if (getRegionScope().isGlobal())
        // skip test under Global
        return;
    if (getRegionScope().isDistributedNoAck())
        // skip test under DistributedNoAck
        return;
    final String name = this.getUniqueName();
    final String roleA = name + "-A";
    final String[] requiredRoles = { roleA };
    Set requiredRolesSet = new HashSet();
    for (int i = 0; i < requiredRoles.length; i++) {
        requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
    }
    assertEquals(requiredRoles.length, requiredRolesSet.size());
    // connect controller to system...
    Properties config = new Properties();
    config.setProperty(ROLES, "");
    getSystem(config);
    GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
    RegionMembershipListener listener = new RegionMembershipListenerAdapter() {

        public void afterRemoteRegionDeparture(RegionEvent event) {
            synchronized (detectedDeparture_testCommitDistributionException) {
                detectedDeparture_testCommitDistributionException[0] = Boolean.TRUE;
                detectedDeparture_testCommitDistributionException.notify();
            }
        }
    };
    // create region in controller...
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.NONE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(getRegionScope());
    fac.addCacheListener(listener);
    RegionAttributes attr = fac.create();
    Region region = createRootRegion(name, attr);
    // use vm1 to create role
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            createConnection(new String[] { roleA });
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            RegionAttributes attr = fac.create();
            createRootRegion(name, attr);
        }
    });
    // define the afterReleaseLocalLocks callback
    SerializableRunnableIF removeRequiredRole = new SerializableRunnableIF() {

        public void run() {
            Host.getHost(0).getVM(1).invoke(new SerializableRunnable("Close Region") {

                public void run() {
                    getRootRegion(name).close();
                }
            });
            try {
                synchronized (detectedDeparture_testCommitDistributionException) {
                    while (detectedDeparture_testCommitDistributionException[0] == Boolean.FALSE) {
                        detectedDeparture_testCommitDistributionException.wait();
                    }
                }
            } catch (InterruptedException e) {
                fail("interrupted");
            }
        }
    };
    // define the add and remove expected exceptions
    final String expectedExceptions = "org.apache.geode.internal.cache.CommitReplyException";
    SerializableRunnable addExpectedExceptions = new CacheSerializableRunnable("addExpectedExceptions") {

        public void run2() throws CacheException {
            getCache().getLogger().info("<ExpectedException action=add>" + expectedExceptions + "</ExpectedException>");
        }
    };
    SerializableRunnable removeExpectedExceptions = new CacheSerializableRunnable("removeExpectedExceptions") {

        public void run2() throws CacheException {
            getCache().getLogger().info("<ExpectedException action=remove>" + expectedExceptions + "</ExpectedException>");
        }
    };
    // perform the actual test...
    CacheTransactionManager ctm = cache.getCacheTransactionManager();
    ctm.begin();
    TXStateInterface txStateProxy = ((TXManagerImpl) ctm).getTXState();
    ((TXStateProxyImpl) txStateProxy).forceLocalBootstrap();
    TXState txState = (TXState) ((TXStateProxyImpl) txStateProxy).getRealDeal(null, null);
    txState.setBeforeSend(() -> {
        try {
            removeRequiredRole.run();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    // now start a transaction and commit it
    region.put("KEY", "VAL");
    addExpectedExceptions.run();
    Host.getHost(0).getVM(1).invoke(addExpectedExceptions);
    try {
        ctm.commit();
        fail("Should have thrown CommitDistributionException");
    } catch (CommitDistributionException e) {
    // pass
    } finally {
        removeExpectedExceptions.run();
        Host.getHost(0).getVM(1).invoke(removeExpectedExceptions);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) TXStateProxyImpl(org.apache.geode.internal.cache.TXStateProxyImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) RegionEvent(org.apache.geode.cache.RegionEvent) SerializableRunnableIF(org.apache.geode.test.dunit.SerializableRunnableIF) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) TXState(org.apache.geode.internal.cache.TXState) AttributesFactory(org.apache.geode.cache.AttributesFactory) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) CommitDistributionException(org.apache.geode.cache.CommitDistributionException) HashSet(java.util.HashSet) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) RegionMembershipListener(org.apache.geode.cache.RegionMembershipListener) TXStateInterface(org.apache.geode.internal.cache.TXStateInterface) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CommitDistributionException(org.apache.geode.cache.CommitDistributionException) RegionDistributionException(org.apache.geode.cache.RegionDistributionException) RegionAccessException(org.apache.geode.cache.RegionAccessException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CacheException(org.apache.geode.cache.CacheException) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionMembershipListenerAdapter(org.apache.geode.cache.util.RegionMembershipListenerAdapter) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 3 with TXStateProxyImpl

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

use of org.apache.geode.internal.cache.TXStateProxyImpl in project geode by apache.

the class TXDistributedDUnitTest method setInternalCallbacks.

static void setInternalCallbacks(TXStateInterface txp, final byte[] cbSensors) {
    ((TXStateProxyImpl) txp).forceLocalBootstrap();
    TXState tx = (TXState) ((TXStateProxyImpl) txp).getRealDeal(null, null);
    assertEquals(9, cbSensors.length);
    tx.setAfterReservation(new Runnable() {

        public void run() {
            cbSensors[0]++;
        }
    });
    tx.setAfterConflictCheck(new Runnable() {

        public void run() {
            cbSensors[1]++;
        }
    });
    tx.setAfterApplyChanges(new Runnable() {

        public void run() {
            cbSensors[2]++;
        }
    });
    tx.setAfterReleaseLocalLocks(new Runnable() {

        public void run() {
            cbSensors[3]++;
        }
    });
    tx.setAfterIndividualSend(new Runnable() {

        public void run() {
            cbSensors[4]++;
        }
    });
    tx.setAfterIndividualCommitProcess(new Runnable() {

        public void run() {
            cbSensors[5]++;
        }
    });
    tx.setAfterSend(new Runnable() {

        public void run() {
            cbSensors[6]++;
        }
    });
    tx.setDuringIndividualSend(new Runnable() {

        public void run() {
            cbSensors[7]++;
        }
    });
    tx.setDuringIndividualCommitProcess(new Runnable() {

        public void run() {
            cbSensors[8]++;
        }
    });
}
Also used : TXState(org.apache.geode.internal.cache.TXState) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) TXStateProxyImpl(org.apache.geode.internal.cache.TXStateProxyImpl)

Aggregations

TXStateProxyImpl (org.apache.geode.internal.cache.TXStateProxyImpl)4 TXState (org.apache.geode.internal.cache.TXState)3 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 CacheException (org.apache.geode.cache.CacheException)2 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)2 Region (org.apache.geode.cache.Region)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 TXManagerImpl (org.apache.geode.internal.cache.TXManagerImpl)2 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)1 CommitDistributionException (org.apache.geode.cache.CommitDistributionException)1 MembershipAttributes (org.apache.geode.cache.MembershipAttributes)1 RegionAccessException (org.apache.geode.cache.RegionAccessException)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 RegionDistributionException (org.apache.geode.cache.RegionDistributionException)1