Search in sources :

Example 6 with ClientServerObserverAdapter

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

the class FailoverDUnitTest method setClientServerObserver.

public static void setClientServerObserver() {
    PoolImpl.BEFORE_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = true;
    ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {

        public void beforePrimaryIdentificationFromBackup() {
            primary.invoke(() -> FailoverDUnitTest.putDuringFailover());
            PoolImpl.BEFORE_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = false;
        }
    });
}
Also used : ClientServerObserverAdapter(org.apache.geode.internal.cache.ClientServerObserverAdapter)

Example 7 with ClientServerObserverAdapter

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

the class DurableResponseMatrixDUnitTest method testRegisterInterest_Destroy_Concurrent.

@Test
public void testRegisterInterest_Destroy_Concurrent() throws Exception {
    PoolImpl.BEFORE_REGISTER_CALLBACK_FLAG = true;
    ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {

        public void beforeInterestRegistration() {
            Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME);
            r.put(KEY, "AgainDummyValue");
            r.destroy(KEY);
            PoolImpl.BEFORE_REGISTER_CALLBACK_FLAG = false;
        }
    });
    Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME);
    r.put(KEY, "DummyValue");
    server1.invoke(() -> DurableResponseMatrixDUnitTest.updateEntry(KEY, "ValueMatrix1"));
    r.registerInterest(KEY, InterestResultPolicy.KEYS_VALUES);
    assertEquals(null, r.getEntry(KEY));
}
Also used : Region(org.apache.geode.cache.Region) ClientServerObserverAdapter(org.apache.geode.internal.cache.ClientServerObserverAdapter) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with ClientServerObserverAdapter

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

the class RedundancyLevelPart3DUnitTest method testRegisterInterestAndMakePrimaryWithFullRedundancy.

/**
   * This tests failing of a primary server in a situation where teh rest of the server are all
   * redundant. After every failure, the order, the dispatcher, the interest registration and the
   * makePrimary calls are verified. The failure detection in these tests could be either through
   * CCU or cache operation, whichever occurs first
   */
@Test
public void testRegisterInterestAndMakePrimaryWithFullRedundancy() {
    try {
        CacheServerTestUtil.disableShufflingOfEndpoints();
        createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), PORT1, PORT2, PORT3, PORT4, 3);
        createEntriesK1andK2();
        registerK1AndK2();
        assertEquals(3, pool.getRedundantNames().size());
        server0.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsAlive());
        server1.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsNotAlive());
        server2.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsNotAlive());
        server3.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsNotAlive());
        server0.invoke(() -> RedundancyLevelTestBase.verifyInterestRegistration());
        server1.invoke(() -> RedundancyLevelTestBase.verifyInterestRegistration());
        server2.invoke(() -> RedundancyLevelTestBase.verifyInterestRegistration());
        server3.invoke(() -> RedundancyLevelTestBase.verifyInterestRegistration());
        PoolImpl.BEFORE_REGISTER_CALLBACK_FLAG = true;
        PoolImpl.BEFORE_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = true;
        PoolImpl.BEFORE_RECOVER_INTEREST_CALLBACK_FLAG = true;
        registerInterestCalled = false;
        makePrimaryCalled = false;
        ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {

            public void beforeInterestRegistration() {
                registerInterestCalled = true;
            }

            public void beforeInterestRecovery() {
                registerInterestCalled = true;
            }

            public void beforePrimaryIdentificationFromBackup() {
                makePrimaryCalled = true;
            }
        });
        server0.invoke(() -> RedundancyLevelTestBase.stopServer());
        doPuts();
        server1.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsAlive());
        server2.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsNotAlive());
        server3.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsNotAlive());
        verifyLiveAndRedundantServers(3, 2);
        if (registerInterestCalled) {
            fail("register interest should not have been called since we failed to a redundant server !");
        }
        if (!makePrimaryCalled) {
            fail("make primary should have been called since primary did fail and a new primary was to be chosen ");
        }
        assertEquals(2, pool.getRedundantNames().size());
        makePrimaryCalled = false;
        server1.invoke(() -> RedundancyLevelTestBase.stopServer());
        doPuts();
        server2.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsAlive());
        server3.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsNotAlive());
        verifyLiveAndRedundantServers(2, 1);
        if (registerInterestCalled) {
            fail("register interest should not have been called since we failed to a redundant server !");
        }
        if (!makePrimaryCalled) {
            fail("make primary should have been called since primary did fail and a new primary was to be chosen ");
        }
        assertEquals(1, pool.getRedundantNames().size());
        makePrimaryCalled = false;
        server2.invoke(() -> RedundancyLevelTestBase.stopServer());
        doPuts();
        server3.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsAlive());
        verifyLiveAndRedundantServers(1, 0);
        if (registerInterestCalled) {
            fail("register interest should not have been called since we failed to a redundant server !");
        }
        if (!makePrimaryCalled) {
            fail("make primary should have been called since primary did fail and a new primary was to be chosen ");
        }
        assertEquals(0, pool.getRedundantNames().size());
        server3.invoke(() -> RedundancyLevelTestBase.stopServer());
        server0.invoke(() -> RedundancyLevelTestBase.startServer());
        doPuts();
        server0.invoke(() -> RedundancyLevelTestBase.verifyDispatcherIsAlive());
        server0.invoke(() -> RedundancyLevelTestBase.verifyInterestRegistration());
        verifyLiveAndRedundantServers(1, 0);
        if (!registerInterestCalled) {
            fail("register interest should have been called since a recovered server came up!");
        }
        assertEquals(0, pool.getRedundantNames().size());
        PoolImpl.BEFORE_REGISTER_CALLBACK_FLAG = false;
        PoolImpl.BEFORE_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = false;
        PoolImpl.BEFORE_RECOVER_INTEREST_CALLBACK_FLAG = false;
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail("test failed due to exception in test testRedundancySpecifiedMoreThanEPs ", ex);
    }
}
Also used : ClientServerObserverAdapter(org.apache.geode.internal.cache.ClientServerObserverAdapter) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 9 with ClientServerObserverAdapter

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

the class Simple2CacheServerDUnitTest method setClientServerObserver.

public static void setClientServerObserver() {
    PoolImpl.AFTER_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = true;
    ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {

        public void afterPrimaryIdentificationFromBackup(ServerLocation primaryEndpoint) {
            LogService.getLogger().info("After primary is set");
            afterPrimaryCount++;
        }
    });
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientServerObserverAdapter(org.apache.geode.internal.cache.ClientServerObserverAdapter)

Example 10 with ClientServerObserverAdapter

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

the class DurableClientSimpleDUnitTest method setPeriodicACKObserver.

private void setPeriodicACKObserver(VM vm) {
    CacheSerializableRunnable cacheSerializableRunnable = new CacheSerializableRunnable("Set ClientServerObserver") {

        @Override
        public void run2() throws CacheException {
            PoolImpl.BEFORE_SENDING_CLIENT_ACK_CALLBACK_FLAG = true;
            ClientServerObserver origObserver = ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {

                @Override
                public void beforeSendingClientAck() {
                    LogWriterUtils.getLogWriter().info("beforeSendingClientAck invoked");
                }
            });
        }
    };
    vm.invoke(cacheSerializableRunnable);
}
Also used : ClientServerObserver(org.apache.geode.internal.cache.ClientServerObserver) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) ClientServerObserverAdapter(org.apache.geode.internal.cache.ClientServerObserverAdapter)

Aggregations

ClientServerObserverAdapter (org.apache.geode.internal.cache.ClientServerObserverAdapter)22 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)5 EventID (org.apache.geode.internal.cache.EventID)4 Region (org.apache.geode.cache.Region)2 ClientServerObserver (org.apache.geode.internal.cache.ClientServerObserver)2 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)1 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 IgnoredException (org.apache.geode.test.dunit.IgnoredException)1