use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class LoggingPerformanceTestCase method performTimeBasedIsEnabledTest.
protected long performTimeBasedIsEnabledTest(final PerformanceLogger perfLogger) {
System.out.println("\nBeginning " + getUniqueName());
final StopWatch stopWatch = new StopWatch(true);
long count = 0;
while (stopWatch.elapsedTimeMillis() < TIME_TO_RUN) {
perfLogger.isEnabled();
count++;
}
stopWatch.stop();
final long millis = stopWatch.elapsedTimeMillis();
final long seconds = millis / 1000;
final long minutes = seconds / 60;
System.out.println(getUniqueName() + " performTimeBasedIsEnabledTest");
System.out.println("Number of isEnabled statements: " + count);
System.out.println("Total elapsed time in millis: " + millis);
System.out.println("Total elapsed time in seconds: " + seconds);
System.out.println("Total elapsed time in minutes: " + minutes);
return millis;
}
use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class OutOfOffHeapMemoryDUnitTest method testOtherMembersSeeOutOfOffHeapMemoryMemberDisconnects.
@Test
public void testOtherMembersSeeOutOfOffHeapMemoryMemberDisconnects() {
final int vmCount = Host.getHost(0).getVMCount();
final String name = getRegionName();
final RegionShortcut shortcut = getRegionShortcut();
final int biggerVM = 0;
final int smallerVM = 1;
Host.getHost(0).getVM(smallerVM).invoke(new SerializableRunnable() {
public void run() {
OutOfOffHeapMemoryDUnitTest.isSmallerVM.set(true);
}
});
// create off-heap region in all members
for (int i = 0; i < vmCount; i++) {
Host.getHost(0).getVM(i).invoke(new SerializableRunnable() {
public void run() {
OutOfOffHeapMemoryDUnitTest.cache.set(getCache());
OutOfOffHeapMemoryDUnitTest.system.set(getSystem());
final Region<Object, Object> region = OutOfOffHeapMemoryDUnitTest.cache.get().createRegionFactory(shortcut).setOffHeap(true).create(name);
assertNotNull(region);
}
});
}
// make sure there are vmCount+1 members total
for (int i = 0; i < vmCount; i++) {
Host.getHost(0).getVM(i).invoke(new SerializableRunnable() {
public void run() {
assertFalse(OutOfOffHeapMemoryDUnitTest.cache.get().isClosed());
assertTrue(OutOfOffHeapMemoryDUnitTest.system.get().isConnected());
// +1 for locator
final int countMembersPlusLocator = vmCount + 1;
// -1 one for self
final int countOtherMembers = vmCount - 1;
assertEquals(countMembersPlusLocator, ((InternalDistributedSystem) OutOfOffHeapMemoryDUnitTest.system.get()).getDistributionManager().getDistributionManagerIds().size());
assertEquals(countOtherMembers, ((DistributedRegion) OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name)).getDistributionAdvisor().getNumProfiles());
}
});
}
// perform puts in bigger member until smaller member goes OOOHME
Host.getHost(0).getVM(biggerVM).invoke(new SerializableRunnable() {
public void run() {
final long TIME_LIMIT = 30 * 1000;
final StopWatch stopWatch = new StopWatch(true);
// -1 for self
int countOtherMembers = vmCount - 1;
// -1 for self, -1 for smallerVM
final int countOtherMembersMinusSmaller = vmCount - 1 - 1;
final Region<Object, Object> region = OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name);
for (int i = 0; countOtherMembers > countOtherMembersMinusSmaller; i++) {
region.put("key-" + i, new byte[1024]);
countOtherMembers = ((DistributedRegion) OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name)).getDistributionAdvisor().getNumProfiles();
assertTrue("puts failed to push member out of off-heap memory within time limit", stopWatch.elapsedTimeMillis() < TIME_LIMIT);
}
assertEquals("Member did not depart from OutOfOffHeapMemory", countOtherMembersMinusSmaller, countOtherMembers);
}
});
// verify that member with OOOHME closed
Host.getHost(0).getVM(smallerVM).invoke(new SerializableRunnable() {
public void run() {
assertTrue(OutOfOffHeapMemoryDUnitTest.cache.get().isClosed());
assertFalse(OutOfOffHeapMemoryDUnitTest.system.get().isConnected());
}
});
// verify that all other members noticed smaller member closed
for (int i = 0; i < vmCount; i++) {
if (i == smallerVM) {
continue;
}
Host.getHost(0).getVM(i).invoke(new SerializableRunnable() {
public void run() {
// +1 for locator, -1 for OOOHME
final int countMembersPlusLocator = vmCount + 1 - 1;
// member
// -1 for self, -1 for OOOHME member
final int countOtherMembers = vmCount - 1 - 1;
with().pollInterval(10, TimeUnit.MILLISECONDS).await().atMost(30, TimeUnit.SECONDS).until(numDistributionManagers(), equalTo(countMembersPlusLocator));
with().pollInterval(10, TimeUnit.MILLISECONDS).await().atMost(30, TimeUnit.SECONDS).until(numProfiles(), equalTo(countOtherMembers));
}
private Callable<Integer> numProfiles() {
return () -> {
DistributedRegion dr = (DistributedRegion) OutOfOffHeapMemoryDUnitTest.cache.get().getRegion(name);
return dr.getDistributionAdvisor().getNumProfiles();
};
}
private Callable<Integer> numDistributionManagers() {
return () -> {
InternalDistributedSystem ids = (InternalDistributedSystem) OutOfOffHeapMemoryDUnitTest.system.get();
return ids.getDistributionManager().getDistributionManagerIds().size();
};
}
});
}
}
use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class QueueManagerJUnitTest method testHandleErrorsOnInit.
@Test
public void testHandleErrorsOnInit() throws Exception {
factory.addError();
factory.addConnection(0, 0, 1);
factory.addError();
factory.addConnection(1, 23, 2);
factory.addError();
factory.addError();
factory.addError();
factory.addConnection(0, 0, 3);
manager = new QueueManagerImpl(pool, endpoints, source, factory, 3, 2000, logger, ClientProxyMembershipID.getNewProxyMembership(ds));
manager.start(background);
// The primary queue can be set before we try to fill in for all of the failed backup servers,
// so we need to wait for the intitialization to finish rather than counting on the
// manager.getAllConnections()
// to wait for a primary
boolean done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 30 * 1000; ) {
Thread.sleep(200);
try {
assertPortEquals(2, manager.getAllConnections().getPrimary());
assertPortEquals(new int[] { 1, 3 }, manager.getAllConnections().getBackups());
manager.close(false);
done = true;
} catch (AssertionError e) {
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue(done);
factory.addError();
factory.addError();
factory.addError();
factory.addError();
factory.addError();
factory.addConnection(0, 0, 1);
factory.addConnection(0, 0, 2);
factory.addConnection(0, 0, 3);
manager = new QueueManagerImpl(pool, endpoints, source, factory, 3, 2000, logger, ClientProxyMembershipID.getNewProxyMembership(ds));
manager.start(background);
// wait for backups to come online.
done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 30 * 1000; ) {
Thread.sleep(200);
try {
assertPortEquals(1, manager.getAllConnections().getPrimary());
assertPortEquals(new int[] { 2, 3 }, manager.getAllConnections().getBackups());
done = true;
} catch (AssertionError e) {
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue(done);
}
use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class ServerBlackListJUnitTest method testBlackListing.
@Test
public void testBlackListing() throws Exception {
ServerLocation location1 = new ServerLocation("localhost", 1);
FailureTracker tracker1 = blackList.getFailureTracker(location1);
tracker1.addFailure();
tracker1.addFailure();
assertEquals(Collections.EMPTY_SET, blackList.getBadServers());
tracker1.addFailure();
assertEquals(Collections.singleton(location1), blackList.getBadServers());
boolean done = false;
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 10000; done = (blackList.getBadServers().size() == 0)) {
Thread.sleep(200);
}
assertTrue("blackList still has bad servers", done);
assertEquals(Collections.EMPTY_SET, blackList.getBadServers());
}
use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class ServerBlackListJUnitTest method testListener.
@Test
public void testListener() throws Exception {
final AtomicInteger adds = new AtomicInteger();
final AtomicInteger removes = new AtomicInteger();
blackList.addListener(new BlackListListenerAdapter() {
@Override
public void serverAdded(ServerLocation location) {
adds.incrementAndGet();
}
@Override
public void serverRemoved(ServerLocation location) {
removes.incrementAndGet();
}
});
ServerLocation location1 = new ServerLocation("localhost", 1);
FailureTracker tracker1 = blackList.getFailureTracker(location1);
tracker1.addFailure();
tracker1.addFailure();
assertEquals(0, adds.get());
assertEquals(0, removes.get());
tracker1.addFailure();
assertEquals(1, adds.get());
assertEquals(0, removes.get());
boolean done = false;
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 10000; done = (removes.get() != 0)) {
Thread.sleep(200);
}
assertTrue("removes still empty", done);
assertEquals(1, adds.get());
assertEquals(1, removes.get());
}
Aggregations