use of org.apache.geode.Statistics in project geode by apache.
the class AtomicStatsJUnitTest method testConcurrentGets.
/**
* Test for bug 41340. Do two gets at the same time of a dirty stat, and make sure we get the
* correct value for the stat.
*
* @throws Throwable
*/
@Test
public void testConcurrentGets() throws Throwable {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
// props.setProperty("statistic-sample-rate", "60000");
props.setProperty(STATISTIC_SAMPLING_ENABLED, "false");
DistributedSystem ds = DistributedSystem.connect(props);
String statName = "TestStats";
String statDescription = "Tests stats";
final String statDesc = "blah blah blah";
StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton();
StatisticsType type = f.createType(statName, statDescription, new StatisticDescriptor[] { f.createIntGauge("stat", statDesc, "bottles of beer on the wall") });
final int statId = type.nameToId("stat");
try {
final AtomicReference<Statistics> statsRef = new AtomicReference<Statistics>();
final CyclicBarrier beforeIncrement = new CyclicBarrier(3);
final CyclicBarrier afterIncrement = new CyclicBarrier(3);
Thread thread1 = new Thread("thread1") {
public void run() {
try {
while (true) {
beforeIncrement.await();
statsRef.get().incInt(statId, 1);
afterIncrement.await();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BrokenBarrierException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
Thread thread3 = new Thread("thread1") {
public void run() {
try {
while (true) {
beforeIncrement.await();
afterIncrement.await();
statsRef.get().getInt(statId);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (BrokenBarrierException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
thread1.start();
thread3.start();
for (int i = 0; i < 5000; i++) {
Statistics stats = ds.createAtomicStatistics(type, "stats");
statsRef.set(stats);
beforeIncrement.await();
afterIncrement.await();
assertEquals("On loop " + i, 1, stats.getInt(statId));
stats.close();
}
} finally {
ds.disconnect();
}
}
use of org.apache.geode.Statistics in project geode by apache.
the class DistributedSystemStatisticsIntegrationTest method setUpLongStatistics.
private Statistics setUpLongStatistics(final int count) {
String[] descriptions = new String[] { "ONE", "TWO", "THREE" };
StatisticDescriptor[] descriptors = new StatisticDescriptor[count];
for (int i = 0; i < count; i++) {
descriptors[i] = factory().createLongGauge(this.statNames[i], descriptions[i], "x");
}
StatisticsType type = factory().createType(getUniqueName(), "", descriptors);
Statistics stats = factory().createStatistics(type, "Display");
for (int i = 0; i < count; i++) {
stats.setLong(this.statNames[i], 0L);
}
return stats;
}
use of org.apache.geode.Statistics in project geode by apache.
the class DistributedSystemStatisticsIntegrationTest method testAccessingDoubleStat.
/**
* Tests that accessing an {@code double} stat throws the appropriate exceptions.
*/
@Test
public void testAccessingDoubleStat() {
Statistics stats = setUpDoubleStatistics(1);
assertThat(stats.getDouble(this.statName1)).isEqualTo(0.0);
assertThatThrownBy(() -> stats.getInt(this.statName1)).isExactlyInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> stats.getLong(this.statName1)).isExactlyInstanceOf(IllegalArgumentException.class);
stats.setDouble(this.statName1, 4.0);
assertThatThrownBy(() -> stats.setInt(this.statName1, 4)).isExactlyInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> stats.setLong(this.statName1, 4L)).isExactlyInstanceOf(IllegalArgumentException.class);
stats.incDouble(this.statName1, 4.0);
assertThatThrownBy(() -> stats.incInt(this.statName1, 4)).isExactlyInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> stats.incLong(this.statName1, 4L)).isExactlyInstanceOf(IllegalArgumentException.class);
}
use of org.apache.geode.Statistics in project geode by apache.
the class DistributedSystemStatisticsIntegrationTest method setUpIntStatistics.
private Statistics setUpIntStatistics(final int count) {
String[] descriptions = new String[] { "ONE", "TWO", "THREE" };
StatisticDescriptor[] descriptors = new StatisticDescriptor[count];
for (int i = 0; i < count; i++) {
descriptors[i] = factory().createIntGauge(this.statNames[i], descriptions[i], "x");
}
StatisticsType type = factory().createType(getUniqueName(), "", descriptors);
Statistics stats = factory().createStatistics(type, "Display");
for (int i = 0; i < count; i++) {
stats.setInt(this.statNames[i], 0);
}
return stats;
}
use of org.apache.geode.Statistics in project geode by apache.
the class ClientMembershipDUnitTest method getAcceptsInProgress.
protected int getAcceptsInProgress() {
StatisticsType st = InternalDistributedSystem.getAnyInstance().findType("CacheServerStats");
Statistics[] s = InternalDistributedSystem.getAnyInstance().findStatisticsByType(st);
return s[0].getInt("acceptsInProgress");
}
Aggregations