Search in sources :

Example 16 with EventID

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

the class ConnectionProxyJUnitTest method testCleanCloseOfThreadIdToSeqId.

@Test
public void testCleanCloseOfThreadIdToSeqId() {
    int port3 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server = null;
    try {
        try {
            server = this.cache.addCacheServer();
            server.setMaximumTimeBetweenPings(10000);
            server.setPort(port3);
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Failed to create server");
        }
        try {
            PoolFactory pf = PoolManager.createFactory();
            pf.addServer("localhost", port3);
            pf.setSubscriptionEnabled(true);
            pf.setSubscriptionRedundancy(-1);
            pf.setSubscriptionMessageTrackingTimeout(100000);
            proxy = (PoolImpl) pf.create("clientPool");
            EventID eid1 = new EventID(new byte[0], 1, 2);
            if (proxy.verifyIfDuplicate(eid1)) {
                fail(" eid can never be duplicate, it is being created for the first time! ");
            }
            EventID eid2 = new EventID(new byte[0], 1, 3);
            if (proxy.verifyIfDuplicate(eid2)) {
                fail(" eid can never be duplicate, since sequenceId is greater ");
            }
            if (!proxy.verifyIfDuplicate(eid2)) {
                fail(" eid had to be a duplicate, since sequenceId is equal ");
            }
            EventID eid3 = new EventID(new byte[0], 1, 1);
            if (!proxy.verifyIfDuplicate(eid3)) {
                fail(" eid had to be a duplicate, since sequenceId is lesser ");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Failed to initialize client");
        }
    } finally {
        if (server != null) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException ie) {
                fail("interrupted");
            }
            server.stop();
        }
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) CacheServer(org.apache.geode.cache.server.CacheServer) EventID(org.apache.geode.internal.cache.EventID) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 17 with EventID

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

the class ConnectionProxyJUnitTest method testThreadIdToSequenceIdMapConcurrency.

@Test
public void testThreadIdToSequenceIdMapConcurrency() {
    int port3 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server = null;
    try {
        try {
            server = this.cache.addCacheServer();
            server.setMaximumTimeBetweenPings(10000);
            server.setPort(port3);
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Failed to create server");
        }
        try {
            PoolFactory pf = PoolManager.createFactory();
            pf.addServer("localhost", port3);
            pf.setSubscriptionEnabled(true);
            pf.setSubscriptionRedundancy(-1);
            pf.setSubscriptionMessageTrackingTimeout(5000);
            pf.setSubscriptionAckInterval(2000);
            proxy = (PoolImpl) pf.create("clientPool");
            // why 10,000?
            final int EVENT_ID_COUNT = 10000;
            EventID[] eid = new EventID[EVENT_ID_COUNT];
            for (int i = 0; i < EVENT_ID_COUNT; i++) {
                eid[i] = new EventID(new byte[0], i, i);
                if (proxy.verifyIfDuplicate(eid[i])) {
                    fail(" eid can never be duplicate, it is being created for the first time! ");
                }
            }
            verifyExpiry(30 * 1000);
            for (int i = 0; i < EVENT_ID_COUNT; i++) {
                if (proxy.verifyIfDuplicate(eid[i])) {
                    fail(" eid can not be found to be  duplicate since the entry should have expired! " + i);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Failed to initialize client");
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) CacheServer(org.apache.geode.cache.server.CacheServer) EventID(org.apache.geode.internal.cache.EventID) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 18 with EventID

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

the class ConnectionProxyJUnitTest method testThreadIdToSequenceIdMapExpiryNegative.

@Test
public void testThreadIdToSequenceIdMapExpiryNegative() {
    int port3 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server = null;
    try {
        try {
            server = this.cache.addCacheServer();
            server.setMaximumTimeBetweenPings(10000);
            server.setPort(port3);
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Failed to create server");
        }
        try {
            PoolFactory pf = PoolManager.createFactory();
            pf.addServer("localhost", port3);
            pf.setSubscriptionEnabled(true);
            pf.setSubscriptionRedundancy(-1);
            pf.setSubscriptionMessageTrackingTimeout(10000);
            proxy = (PoolImpl) pf.create("clientPool");
            final EventID eid = new EventID(new byte[0], 1, 1);
            if (proxy.verifyIfDuplicate(eid)) {
                fail(" eid should not be duplicate as it is a new entry");
            }
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return proxy.verifyIfDuplicate(eid);
                }

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, 20 * 1000, 200, true);
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Failed to initialize client");
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheServer(org.apache.geode.cache.server.CacheServer) EventID(org.apache.geode.internal.cache.EventID) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 19 with EventID

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

the class ClientsWithVersioningRetryDUnitTest method testRetryPut.

/**
   * Test that we can successfully retry a distributed put all and get the version information.
   * second failure in bug 44951
   */
@Test
public void testRetryPut() {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    createServerRegion(vm0, RegionShortcut.REPLICATE);
    createServerRegion(vm1, RegionShortcut.REPLICATE);
    // create an event tag in vm0 and then replay that event in vm1
    final DistributedMember memberID = (DistributedMember) vm0.invoke(new SerializableCallable("get id") {

        public Object call() {
            return ((DistributedRegion) getCache().getRegion("region")).getDistributionManager().getDistributionManagerId();
        }
    });
    vm0.invoke(new SerializableCallable("create entry with fake event ID") {

        @Override
        public Object call() {
            DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
            VersionTag tag = new VMVersionTag();
            tag.setMemberID(dr.getVersionMember());
            tag.setRegionVersion(123);
            tag.setEntryVersion(9);
            tag.setVersionTimeStamp(System.currentTimeMillis());
            EventID eventID = new EventID(new byte[0], 1, 0);
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
            event.setVersionTag(tag);
            event.setContext(new ClientProxyMembershipID(memberID));
            dr.recordEvent(event);
            event.release();
            return memberID;
        }
    });
    vm1.invoke(new SerializableRunnable("recover event tag in vm1 from vm0") {

        @Override
        public void run() {
            DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
            EventID eventID = new EventID(new byte[0], 1, 0);
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
            try {
                event.setContext(new ClientProxyMembershipID(memberID));
                boolean recovered = ((BaseCommand) Put70.getCommand()).recoverVersionTagForRetriedOperation(event);
                assertTrue("Expected to recover the version for this event ID", recovered);
                assertEquals("Expected the region version to be 123", 123, event.getVersionTag().getRegionVersion());
            } finally {
                event.release();
            }
        }
    });
    // bug #48205 - a retried op in PR nodes not owning the primary bucket
    // may already have a version assigned to it in another backup bucket
    vm1.invoke(new SerializableRunnable("recover posdup event tag in vm1 event tracker from vm0") {

        @Override
        public void run() {
            DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
            EventID eventID = new EventID(new byte[0], 1, 0);
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
            event.setPossibleDuplicate(true);
            try {
                dr.hasSeenEvent(event);
                assertTrue("Expected to recover the version for the event ID", event.getVersionTag() != null);
            } finally {
                event.release();
            }
        }
    });
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedMember(org.apache.geode.distributed.DistributedMember) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EventID(org.apache.geode.internal.cache.EventID) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 20 with EventID

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

the class HARegionQueueJUnitTest method testExpiryPositive.

/**
   * tests whether expiry of entry in the region queue occurs as expected
   */
@Test
public void testExpiryPositive() throws Exception {
    HARegionQueueAttributes haa = new HARegionQueueAttributes();
    haa.setExpiryTime(1);
    HARegionQueue regionQueue = createHARegionQueue(this.testName.getMethodName(), haa);
    long start = System.currentTimeMillis();
    regionQueue.put(new ConflatableObject("key", "value", new EventID(new byte[] { 1 }, 1, 1), true, this.testName.getMethodName()));
    Map map = (Map) regionQueue.getConflationMapForTesting().get(this.testName.getMethodName());
    waitAtLeast(1000, start, () -> {
        assertThat(map, is(Collections.emptyMap()));
        assertThat(regionQueue.getRegion().keys(), is(Collections.emptySet()));
    });
}
Also used : EventID(org.apache.geode.internal.cache.EventID) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

EventID (org.apache.geode.internal.cache.EventID)147 Test (org.junit.Test)66 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)58 IOException (java.io.IOException)41 Map (java.util.Map)33 CacheException (org.apache.geode.cache.CacheException)31 Conflatable (org.apache.geode.internal.cache.Conflatable)29 LocalRegion (org.apache.geode.internal.cache.LocalRegion)23 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)20 HashMap (java.util.HashMap)16 Part (org.apache.geode.internal.cache.tier.sockets.Part)16 ByteBuffer (java.nio.ByteBuffer)14 Iterator (java.util.Iterator)14 List (java.util.List)14 LinkedHashMap (java.util.LinkedHashMap)13 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)13 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12