use of com.google.common.eventbus.EventBus in project guava by google.
the class OutsideEventBusTest method testAnonymous.
/*
* If you do this test from common.eventbus.EventBusTest, it doesn't actually test the behavior.
* That is, even if exactly the same method works from inside the common.eventbus package tests,
* it can fail here.
*/
public void testAnonymous() {
final AtomicReference<String> holder = new AtomicReference<String>();
final AtomicInteger deliveries = new AtomicInteger();
EventBus bus = new EventBus();
bus.register(new Object() {
@Subscribe
public void accept(String str) {
holder.set(str);
deliveries.incrementAndGet();
}
});
String EVENT = "Hello!";
bus.post(EVENT);
assertEquals("Only one event should be delivered.", 1, deliveries.get());
assertEquals("Correct string should be delivered.", EVENT, holder.get());
}
use of com.google.common.eventbus.EventBus in project graylog2-server by Graylog2.
the class EventBusProvider method get.
@Override
public EventBus get() {
final EventBus eventBus = new AsyncEventBus("graylog-eventbus", executorService(configuration.getAsyncEventbusProcessors()));
eventBus.register(new DeadEventLoggingListener());
return eventBus;
}
use of com.google.common.eventbus.EventBus in project graylog2-server by Graylog2.
the class StaticFieldFilterTest method testFilterIsNotOverwritingExistingKeys.
@Test
@SuppressForbidden("Executors#newSingleThreadExecutor() is okay for tests")
public void testFilterIsNotOverwritingExistingKeys() throws Exception {
Message msg = new Message("hello", "junit", Tools.nowUTC());
msg.addField("foo", "IWILLSURVIVE");
final StaticFieldFilter filter = new StaticFieldFilter(inputService, new EventBus(), Executors.newSingleThreadScheduledExecutor());
filter.filter(msg);
assertEquals("hello", msg.getMessage());
assertEquals("junit", msg.getSource());
assertEquals("IWILLSURVIVE", msg.getField("foo"));
}
use of com.google.common.eventbus.EventBus in project graylog2-server by Graylog2.
the class MongoIndexRangeServiceTest method setUp.
@Before
public void setUp() throws Exception {
localEventBus = new EventBus("local-event-bus");
indexRangeService = new MongoIndexRangeService(mongoRule.getMongoConnection(), objectMapperProvider, indices, indexSetRegistry, new NullAuditEventSender(), mock(NodeId.class), localEventBus);
}
use of com.google.common.eventbus.EventBus in project graylog2-server by Graylog2.
the class KafkaJournalTest method setUp.
@Before
public void setUp() throws IOException {
scheduler = new ScheduledThreadPoolExecutor(1);
scheduler.prestartCoreThread();
journalDirectory = temporaryFolder.newFolder();
final File nodeId = temporaryFolder.newFile("node-id");
Files.write(UUID.randomUUID().toString(), nodeId, StandardCharsets.UTF_8);
final Configuration configuration = new Configuration() {
@Override
public String getNodeIdFile() {
return nodeId.getAbsolutePath();
}
};
serverStatus = new ServerStatus(configuration, EnumSet.of(ServerStatus.Capability.MASTER), new EventBus("KafkaJournalTest"), NullAuditEventSender::new);
}
Aggregations