use of com.facebook.buck.testutil.FakeExecutor in project buck by facebook.
the class CounterRegistryImplTest method noEventsFlushedIfCounterRegisteredButHasNoData.
@Test
public void noEventsFlushedIfCounterRegisteredButHasNoData() throws IOException {
BuckEventBus fakeEventBus = new BuckEventBus(new FakeClock(0), false, new BuildId("12345"), 1000);
SnapshotEventListener listener = new SnapshotEventListener();
fakeEventBus.register(listener);
FakeExecutor fakeExecutor = new FakeExecutor();
try (CounterRegistryImpl registry = new CounterRegistryImpl(fakeExecutor, fakeEventBus)) {
registry.newIntegerCounter(CATEGORY, NAME, TAGS);
assertThat("No events should be flushed before timer fires", listener.snapshotEvents, empty());
fakeExecutor.drain();
assertThat("No events should be flushed after timer fires when counter has no data", listener.snapshotEvents, empty());
}
assertThat("No events should be flushed after registry closed", listener.snapshotEvents, empty());
}
use of com.facebook.buck.testutil.FakeExecutor in project buck by facebook.
the class CounterRegistryImplTest method noEventsFlushedIfNoCountersRegistered.
@Test
public void noEventsFlushedIfNoCountersRegistered() throws IOException {
BuckEventBus fakeEventBus = new BuckEventBus(new FakeClock(0), false, new BuildId("12345"), 1000);
SnapshotEventListener listener = new SnapshotEventListener();
fakeEventBus.register(listener);
FakeExecutor fakeExecutor = new FakeExecutor();
try (CounterRegistryImpl registry = new CounterRegistryImpl(fakeExecutor, fakeEventBus)) {
assertThat("No events should be flushed before timer fires", listener.snapshotEvents, empty());
fakeExecutor.drain();
assertThat("No events should be flushed after timer fires", listener.snapshotEvents, empty());
}
assertThat("No events should be flushed after registry closed", listener.snapshotEvents, empty());
}
use of com.facebook.buck.testutil.FakeExecutor in project buck by facebook.
the class CounterRegistryImplTest method eventIsFlushedIfCounterRegisteredWithData.
@Test
public void eventIsFlushedIfCounterRegisteredWithData() throws IOException {
BuckEventBus fakeEventBus = new BuckEventBus(new FakeClock(0), false, new BuildId("12345"), 1000);
SnapshotEventListener listener = new SnapshotEventListener();
fakeEventBus.register(listener);
FakeExecutor fakeExecutor = new FakeExecutor();
try (CounterRegistryImpl registry = new CounterRegistryImpl(fakeExecutor, fakeEventBus)) {
IntegerCounter counter = registry.newIntegerCounter(CATEGORY, NAME, TAGS);
counter.inc(42);
assertThat("No events should be flushed before timer fires", listener.snapshotEvents, empty());
fakeExecutor.drain();
assertThat("One event should be flushed after timer fires", listener.snapshotEvents, hasSize(1));
assertThat("Counter with expected value should be flushed after timer fires", listener.snapshotEvents.get(0).getSnapshots(), hasItem(CounterSnapshot.builder().setCategory(CATEGORY).setTags(TAGS).putValues(NAME, 42).build()));
}
}
use of com.facebook.buck.testutil.FakeExecutor in project buck by facebook.
the class CounterRegistryImplTest method closingRegistryBeforeTimerFiresFlushesCounters.
@Test
public void closingRegistryBeforeTimerFiresFlushesCounters() throws IOException {
BuckEventBus fakeEventBus = new BuckEventBus(new FakeClock(0), false, new BuildId("12345"), 1000);
SnapshotEventListener listener = new SnapshotEventListener();
fakeEventBus.register(listener);
FakeExecutor fakeExecutor = new FakeExecutor();
try (CounterRegistryImpl registry = new CounterRegistryImpl(fakeExecutor, fakeEventBus)) {
IntegerCounter counter = registry.newIntegerCounter(CATEGORY, NAME, TAGS);
counter.inc(42);
assertThat("No events should be flushed before timer fires", listener.snapshotEvents, empty());
}
// We explicitly do not call fakeExecutor.drain() here, because we want to simulate what
// happens when the registry is closed before the executor fires.
assertThat("One snapshot event should be flushed when registry closed before timer fires", listener.snapshotEvents, hasSize(1));
assertThat("Expected snapshot should be flushed when registry closed before timer fires", listener.snapshotEvents.get(0).getSnapshots(), hasItem(CounterSnapshot.builder().setCategory(CATEGORY).setTags(TAGS).putValues(NAME, 42).build()));
}
Aggregations