Search in sources :

Example 1 with FakeExecutor

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());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeExecutor(com.facebook.buck.testutil.FakeExecutor) FakeClock(com.facebook.buck.timing.FakeClock) Test(org.junit.Test)

Example 2 with FakeExecutor

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());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeExecutor(com.facebook.buck.testutil.FakeExecutor) FakeClock(com.facebook.buck.timing.FakeClock) Test(org.junit.Test)

Example 3 with FakeExecutor

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()));
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeExecutor(com.facebook.buck.testutil.FakeExecutor) FakeClock(com.facebook.buck.timing.FakeClock) Test(org.junit.Test)

Example 4 with FakeExecutor

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()));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeExecutor(com.facebook.buck.testutil.FakeExecutor) FakeClock(com.facebook.buck.timing.FakeClock) Test(org.junit.Test)

Aggregations

BuckEventBus (com.facebook.buck.event.BuckEventBus)4 BuildId (com.facebook.buck.model.BuildId)4 FakeExecutor (com.facebook.buck.testutil.FakeExecutor)4 FakeClock (com.facebook.buck.timing.FakeClock)4 Test (org.junit.Test)4