Search in sources :

Example 86 with EventID

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

the class HAEventIdPropagationDUnitTest method assertThreadIdToSequenceIdMapHasEntryIds.

/**
   * function to assert that the ThreadIdtoSequence id Map is not Null and has only one entry *
   */
public static Object[] assertThreadIdToSequenceIdMapHasEntryIds() {
    EventID[] evids = new EventID[5];
    Map map = pool.getThreadIdToSequenceIdMap();
    assertNotNull(map);
    evids[0] = putAlleventId1;
    evids[1] = putAlleventId2;
    evids[2] = putAlleventId3;
    evids[3] = putAlleventId4;
    evids[4] = putAlleventId5;
    assertNotNull(evids[0]);
    assertNotNull(evids[1]);
    assertNotNull(evids[2]);
    assertNotNull(evids[3]);
    assertNotNull(evids[4]);
    return evids;
}
Also used : EventID(org.apache.geode.internal.cache.EventID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 87 with EventID

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

the class HAEventIdPropagationDUnitTest method assertThreadIdToSequenceIdMapHasEntryId.

/**
   * function to assert that the ThreadIdtoSequence id Map is not Null and has only one entry *
   */
public static Object assertThreadIdToSequenceIdMapHasEntryId() {
    Map map = pool.getThreadIdToSequenceIdMap();
    assertNotNull(map);
    // The map size can now be 1 or 2 because of the server thread putting
    // the marker in the queue. If it is 2, the first entry is the server
    // thread; the second is the client thread. If it is 1, the entry is the
    // client thread. The size changes because of the map.clear call below.
    assertTrue(map.size() != 0);
    // Set the entry to the last entry
    Map.Entry entry = null;
    for (Iterator threadIdToSequenceIdMapIterator = map.entrySet().iterator(); threadIdToSequenceIdMapIterator.hasNext(); ) {
        entry = (Map.Entry) threadIdToSequenceIdMapIterator.next();
    }
    ThreadIdentifier tid = (ThreadIdentifier) entry.getKey();
    SequenceIdAndExpirationObject seo = (SequenceIdAndExpirationObject) entry.getValue();
    long sequenceId = seo.getSequenceId();
    EventID evId = new EventID(tid.getMembershipID(), tid.getThreadID(), sequenceId);
    synchronized (map) {
        map.clear();
    }
    return evId;
}
Also used : SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) Iterator(java.util.Iterator) EventID(org.apache.geode.internal.cache.EventID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 88 with EventID

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

the class HAEventIdPropagationDUnitTest method testEventIDPropagation.

/**
   * This test: 1) creates a client server configuration 2) asserts that the ThreadIdToSequenceIdMap
   * is not null but is empty (on the client) 3) does a operation on the server 4) Wait till
   * operation is received by the server (and also records the eventId in a variable) and returns
   * the eventId generated on the server 5) asserts that the ThreadIdToSequenceIdMap is not null and
   * has one entry (on the client side) and returns the eventId stored in the map 6) verifies the
   * equality of the two event ids
   */
@Test
public void testEventIDPropagation() throws Exception {
    try {
        createClientServerConfiguration();
        client1.invoke(() -> HAEventIdPropagationDUnitTest.setReceivedOperationToFalse());
        client1.invoke(() -> HAEventIdPropagationDUnitTest.assertThreadIdToSequenceIdMapisNotNullButEmpty());
        Object eventId1 = server1.invoke(() -> HAEventIdPropagationDUnitTest.putKey1Val1());
        assertNotNull(eventId1);
        // wait for key to propagate till client
        // assert map not null on client
        client1.invoke(() -> HAEventIdPropagationDUnitTest.waitTillOperationReceived());
        Object eventId2 = client1.invoke(() -> HAEventIdPropagationDUnitTest.assertThreadIdToSequenceIdMapHasEntryId());
        assertNotNull(eventId2);
        if (!eventId1.equals(eventId2)) {
            fail("Test failed as the eventIds are not equal");
        }
        client1.invoke(() -> HAEventIdPropagationDUnitTest.setReceivedOperationToFalse());
        eventId1 = server1.invoke(() -> HAEventIdPropagationDUnitTest.updateKey1());
        assertNotNull(eventId1);
        // wait for key to propagate till client
        // assert map not null on client
        client1.invoke(() -> HAEventIdPropagationDUnitTest.waitTillOperationReceived());
        eventId2 = client1.invoke(() -> HAEventIdPropagationDUnitTest.assertThreadIdToSequenceIdMapHasEntryId());
        assertNotNull(eventId2);
        if (!eventId1.equals(eventId2)) {
            fail("Test failed as the eventIds are not equal");
        }
        client1.invoke(() -> HAEventIdPropagationDUnitTest.setReceivedOperationToFalse());
        eventId1 = server1.invoke(() -> HAEventIdPropagationDUnitTest.invalidateKey1());
        assertNotNull(eventId1);
        // wait for key to propagate till client
        // assert map not null on client
        client1.invoke(() -> HAEventIdPropagationDUnitTest.waitTillOperationReceived());
        eventId2 = client1.invoke(() -> HAEventIdPropagationDUnitTest.assertThreadIdToSequenceIdMapHasEntryId());
        assertNotNull(eventId2);
        if (!eventId1.equals(eventId2)) {
            fail("Test failed as the eventIds are not equal");
        }
        client1.invoke(() -> HAEventIdPropagationDUnitTest.setReceivedOperationToFalse());
        EventID[] eventIds1 = (EventID[]) server1.invoke(() -> HAEventIdPropagationDUnitTest.putAll());
        assertNotNull(eventIds1);
        // wait for key to propagate till client
        // assert map not null on client
        client1.invoke(() -> HAEventIdPropagationDUnitTest.waitTillOperationReceived());
        EventID[] eventIds2 = (EventID[]) client1.invoke(() -> HAEventIdPropagationDUnitTest.assertThreadIdToSequenceIdMapHasEntryIds());
        assertNotNull(eventIds2);
        for (int i = 0; i < 5; i++) {
            assertNotNull(eventIds1[i]);
            assertNotNull(eventIds2[i]);
            if (!eventIds1[i].equals(eventIds2[i])) {
                fail(" eventIds are not equal");
            }
        }
        client1.invoke(() -> HAEventIdPropagationDUnitTest.setReceivedOperationToFalse());
        eventId1 = server1.invoke(() -> HAEventIdPropagationDUnitTest.removePUTALL_KEY1());
        assertNotNull(eventId1);
        // wait for key to propagate till client
        // assert map not null on client
        client1.invoke(() -> HAEventIdPropagationDUnitTest.waitTillOperationReceived());
        eventId2 = client1.invoke(() -> HAEventIdPropagationDUnitTest.assertThreadIdToSequenceIdMapHasEntryId());
        assertNotNull(eventId2);
        if (!eventId1.equals(eventId2)) {
            fail("Test failed as the eventIds are not equal");
        }
        client1.invoke(() -> HAEventIdPropagationDUnitTest.setReceivedOperationToFalse());
        eventId1 = server1.invoke(() -> HAEventIdPropagationDUnitTest.destroyKey1());
        assertNotNull(eventId1);
        // wait for key to propagate till client
        // assert map not null on client
        client1.invoke(() -> HAEventIdPropagationDUnitTest.waitTillOperationReceived());
        eventId2 = client1.invoke(() -> HAEventIdPropagationDUnitTest.assertThreadIdToSequenceIdMapHasEntryId());
        assertNotNull(eventId2);
        if (!eventId1.equals(eventId2)) {
            fail("Test failed as the eventIds are not equal");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("test failed due to " + e, e);
    }
}
Also used : EventID(org.apache.geode.internal.cache.EventID) SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) CacheException(org.apache.geode.cache.CacheException) ConflationDUnitTest(org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 89 with EventID

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

the class EventIdOptimizationDUnitTest method assertThreadIdToSequenceIdMapHasEntryId.

/**
   * Function to assert that the ThreadIdtoSequence id Map is not Null and has only one entry.
   * 
   * @return - eventID object from the ThreadIdToSequenceIdMap
   */
public static Object assertThreadIdToSequenceIdMapHasEntryId() {
    Map map = pool.getThreadIdToSequenceIdMap();
    assertNotNull(map);
    // The map size can now be 1 or 2 because of the server thread putting
    // the marker in the queue. If it is 2, the first entry is the server
    // thread; the second is the client thread. If it is 1, the entry is the
    // client thread. The size changes because of the map.clear call below.
    assertTrue(map.size() != 0);
    // Set the entry to the last entry
    Map.Entry entry = null;
    for (Iterator threadIdToSequenceIdMapIterator = map.entrySet().iterator(); threadIdToSequenceIdMapIterator.hasNext(); ) {
        entry = (Map.Entry) threadIdToSequenceIdMapIterator.next();
    }
    ThreadIdentifier tid = (ThreadIdentifier) entry.getKey();
    SequenceIdAndExpirationObject seo = (SequenceIdAndExpirationObject) entry.getValue();
    long sequenceId = seo.getSequenceId();
    EventID evId = new EventID(tid.getMembershipID(), tid.getThreadID(), sequenceId);
    synchronized (map) {
        map.clear();
    }
    return evId;
}
Also used : SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) Iterator(java.util.Iterator) EventID(org.apache.geode.internal.cache.EventID) Map(java.util.Map)

Example 90 with EventID

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

the class SerialGatewaySenderImpl method setModifiedEventId.

@Override
protected void setModifiedEventId(EntryEventImpl clonedEvent) {
    EventID originalEventId = clonedEvent.getEventId();
    long originalThreadId = originalEventId.getThreadID();
    long newThreadId = originalThreadId;
    if (ThreadIdentifier.isWanTypeThreadID(newThreadId)) {
    // This thread id has already been converted. Do nothing.
    } else {
        newThreadId = ThreadIdentifier.createFakeThreadIDForParallelGSPrimaryBucket(0, originalThreadId, getEventIdIndex());
    }
    EventID newEventId = new EventID(originalEventId.getMembershipID(), newThreadId, originalEventId.getSequenceID());
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Generated event id for event with key={}, original event id={}, originalThreadId={}, new event id={}, newThreadId={}", this, clonedEvent.getKey(), originalEventId, originalThreadId, newEventId, newThreadId);
    }
    clonedEvent.setEventId(newEventId);
}
Also used : EventID(org.apache.geode.internal.cache.EventID)

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