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