use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class GemFireStatSamplerIntegrationTest method testArchiveRemoval.
/**
* Verifies that archive removal works correctly when archive-disk-space-limit is specified.
*/
// GEODE-2286: need to rewrite with Awaitility and longer timeouts
@Category(FlakyTest.class)
@Test
public void testArchiveRemoval() throws Exception {
// + File.separator + this.testName;
final String dirName = this.testDir.getAbsolutePath();
new File(dirName).mkdirs();
final String archiveFileName = dirName + File.separator + this.testName + ".gfs";
final File archiveFile = new File(archiveFileName);
final File archiveFile1 = new File(dirName + File.separator + this.testName + "-01-01.gfs");
final File archiveFile2 = new File(dirName + File.separator + this.testName + "-01-02.gfs");
final File archiveFile3 = new File(dirName + File.separator + this.testName + "-01-03.gfs");
final File archiveFile4 = new File(dirName + File.separator + this.testName + "-01-04.gfs");
final int sampleRate = 1000;
// set the system property to use KB instead of MB for file size
System.setProperty(HostStatSampler.TEST_FILE_SIZE_LIMIT_IN_KB_PROPERTY, "true");
Properties props = createGemFireProperties();
props.setProperty(STATISTIC_ARCHIVE_FILE, archiveFileName);
props.setProperty(ARCHIVE_FILE_SIZE_LIMIT, "1");
props.setProperty(ARCHIVE_DISK_SPACE_LIMIT, "12");
props.setProperty(STATISTIC_SAMPLE_RATE, String.valueOf(sampleRate));
connect(props);
assertTrue(getGemFireStatSampler().waitForInitialization(5000));
boolean exists1 = false;
boolean exists2 = false;
boolean exists3 = false;
boolean exists4 = false;
boolean exists = false;
boolean done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 10 * sampleRate; ) {
exists1 = exists1 || archiveFile1.exists();
exists2 = exists2 || archiveFile2.exists();
exists3 = exists3 || archiveFile3.exists();
exists4 = exists4 || archiveFile4.exists();
exists = exists || archiveFile.exists();
done = exists1 && exists2 && exists3 && exists4 && exists;
if (!done) {
Thread.sleep(10);
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue("Waiting for archive files to exist:" + " exists1=" + exists1 + " exists2=" + exists2 + " exists3=" + exists3 + " exists4=" + exists4 + " exists=" + exists, done);
waitForFileToDelete(archiveFile1, 10 * sampleRate, 10);
}
use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class GemFireStatSamplerIntegrationTest method testArchiveRolling.
/**
* Verifies that archive rolling works correctly when archive-file-size-limit is specified.
*/
@Test
public void testArchiveRolling() throws Exception {
final String dirName = this.testDir.getAbsolutePath() + File.separator + this.testName;
new File(dirName).mkdirs();
final String archiveFileName = dirName + File.separator + this.testName + ".gfs";
final File archiveFile = new File(archiveFileName);
final File archiveFile1 = new File(dirName + File.separator + this.testName + "-01-01.gfs");
final File archiveFile2 = new File(dirName + File.separator + this.testName + "-01-02.gfs");
final File archiveFile3 = new File(dirName + File.separator + this.testName + "-01-03.gfs");
// set the system property to use KB instead of MB for file size
System.setProperty(HostStatSampler.TEST_FILE_SIZE_LIMIT_IN_KB_PROPERTY, "true");
Properties props = createGemFireProperties();
props.setProperty(ARCHIVE_FILE_SIZE_LIMIT, "1");
props.setProperty(ARCHIVE_DISK_SPACE_LIMIT, "0");
props.setProperty(STATISTIC_ARCHIVE_FILE, archiveFileName);
connect(props);
assertTrue(getGemFireStatSampler().waitForInitialization(5000));
boolean done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 4000; done = (getSampleCollector() != null && getSampleCollector().getStatArchiveHandler() != null)) {
Thread.sleep(10);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue("Waiting for getSampleCollector().getStatArchiveHandler() to not be null", done);
StatArchiveHandler statArchiveHandler = getSampleCollector().getStatArchiveHandler();
StatArchiveHandlerConfig config = statArchiveHandler.getStatArchiveHandlerConfig();
assertEquals(1 * 1024, config.getArchiveFileSizeLimit());
waitForFileToExist(archiveFile, 4000, 10);
waitForFileToExist(archiveFile1, 4000, 10);
waitForFileToExist(archiveFile2, 4000, 10);
waitForFileToExist(archiveFile3, 4000, 10);
}
use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class GemFireStatSamplerIntegrationTest method testLocalStatListener.
/**
* Adds a LocalStatListener for an individual stat. Validates that it receives notifications.
* Removes the listener and validates that it was in fact removed and no longer receives
* notifications.
*/
@Test
public void testLocalStatListener() throws Exception {
connect(createGemFireProperties());
GemFireStatSampler statSampler = getGemFireStatSampler();
assertTrue(statSampler.waitForInitialization(5000));
Method getLocalListeners = getGemFireStatSampler().getClass().getMethod("getLocalListeners");
assertNotNull(getLocalListeners);
Method addLocalStatListener = getGemFireStatSampler().getClass().getMethod("addLocalStatListener", LocalStatListener.class, Statistics.class, String.class);
assertNotNull(addLocalStatListener);
Method removeLocalStatListener = getGemFireStatSampler().getClass().getMethod("removeLocalStatListener", LocalStatListener.class);
assertNotNull(removeLocalStatListener);
// validate that there are no listeners
assertTrue(statSampler.getLocalListeners().isEmpty());
// add a listener for sampleCount stat in StatSampler statistics
StatisticsType statSamplerType = getStatisticsManager().findType("StatSampler");
Statistics[] statsArray = getStatisticsManager().findStatisticsByType(statSamplerType);
assertEquals(1, statsArray.length);
final Statistics statSamplerStats = statsArray[0];
final String statName = "sampleCount";
final AtomicInteger sampleCountValue = new AtomicInteger(0);
final AtomicInteger sampleCountChanged = new AtomicInteger(0);
LocalStatListener listener = new LocalStatListener() {
public void statValueChanged(double value) {
sampleCountValue.set((int) value);
sampleCountChanged.incrementAndGet();
}
};
statSampler.addLocalStatListener(listener, statSamplerStats, statName);
assertTrue(statSampler.getLocalListeners().size() == 1);
// there's a level of indirection here and some protected member fields
LocalStatListenerImpl lsli = (LocalStatListenerImpl) statSampler.getLocalListeners().iterator().next();
assertEquals("sampleCount", lsli.stat.getName());
// wait for the listener to update 4 times
final int expectedChanges = 4;
boolean done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 5000; done = (sampleCountChanged.get() >= expectedChanges)) {
Thread.sleep(10);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue("Waiting for sampleCountChanged >= " + expectedChanges, done);
// validate that the listener fired and updated the value
assertTrue(sampleCountValue.get() > 0);
assertTrue(sampleCountChanged.get() >= expectedChanges);
// remove the listener
statSampler.removeLocalStatListener(listener);
final int expectedSampleCountValue = sampleCountValue.get();
final int expectedSampleCountChanged = sampleCountChanged.get();
// validate that there are no listeners now
assertTrue(statSampler.getLocalListeners().isEmpty());
// wait for 2 stat samples to occur
waitForStatSample(statSamplerStats, expectedSampleCountValue, 5000, 10);
// validate that the listener did not fire
assertEquals(expectedSampleCountValue, sampleCountValue.get());
assertEquals(expectedSampleCountChanged, sampleCountChanged.get());
}
use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class GemFireStatSamplerIntegrationTest method testLocalStatListenerRegistration.
@Test
public void testLocalStatListenerRegistration() throws Exception {
connect(createGemFireProperties());
final GemFireStatSampler statSampler = getGemFireStatSampler();
statSampler.waitForInitialization(5000);
final AtomicBoolean flag = new AtomicBoolean(false);
final LocalStatListener listener = new LocalStatListener() {
public void statValueChanged(double value) {
flag.set(true);
}
};
final String tenuredPoolName = HeapMemoryMonitor.getTenuredMemoryPoolMXBean().getName();
logger.info("TenuredPoolName: {}", tenuredPoolName);
final List<Statistics> list = ((StatisticsManager) this.system).getStatsList();
assertFalse(list.isEmpty());
boolean done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 5000; ) {
Thread.sleep(10);
int i = 0;
synchronized (list) {
for (Object obj : list) {
++i;
logger.info("List:{}:{}", i, obj);
if (obj instanceof StatisticsImpl) {
StatisticsImpl si = (StatisticsImpl) obj;
logger.info("stat:{}", si.getTextId());
if (si.getTextId().contains(tenuredPoolName)) {
statSampler.addLocalStatListener(listener, si, "currentUsedMemory");
done = true;
}
}
}
}
// done = false;
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue("Waiting for " + tenuredPoolName + " statistics to be added to create listener for", done);
assertTrue("expected at least one stat listener, found " + statSampler.getLocalListeners().size(), statSampler.getLocalListeners().size() > 0);
long maxTenuredMemory = HeapMemoryMonitor.getTenuredMemoryPoolMXBean().getUsage().getMax();
// byte[] bytes = new byte[1024 * 1024 * 10];
byte[] bytes = new byte[(int) (maxTenuredMemory * 0.01)];
Arrays.fill(bytes, Byte.MAX_VALUE);
done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 5000; done = (flag.get())) {
Thread.sleep(10);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue("Waiting for listener to set flag to true", done);
}
use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class StatSamplerTestCase method waitForExpectedStatValue.
protected static void waitForExpectedStatValue(final Statistics statSamplerStats, final String statName, final int expectedStatValue, final long millis, final long sleep) {
boolean done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < millis; done = (statSamplerStats.getInt(statName) >= expectedStatValue)) {
Thread.sleep(sleep);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue("Waiting for " + statName + " >= " + expectedStatValue, done);
}
Aggregations