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;
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations