Search in sources :

Example 1 with ClusterEventBus

use of org.graylog2.events.ClusterEventBus in project graylog2-server by Graylog2.

the class V20161215163900_MoveIndexSetDefaultConfigTest method setUp.

@Before
public void setUp() throws Exception {
    this.clusterConfigService = spy(new ClusterConfigServiceImpl(objectMapperProvider, fongoRule.getConnection(), nodeId, new ChainingClassLoader(getClass().getClassLoader()), new ClusterEventBus()));
    this.collection = fongoRule.getDatabase().getCollection("index_sets");
    this.migration = new V20161215163900_MoveIndexSetDefaultConfig(fongoRule.getConnection(), clusterConfigService);
}
Also used : ClusterConfigServiceImpl(org.graylog2.cluster.ClusterConfigServiceImpl) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) ClusterEventBus(org.graylog2.events.ClusterEventBus) Before(org.junit.Before)

Example 2 with ClusterEventBus

use of org.graylog2.events.ClusterEventBus in project graylog2-server by Graylog2.

the class V20161116172200_CreateDefaultStreamMigrationTest method upgradePostsStreamsChangedEvent.

@Test
public void upgradePostsStreamsChangedEvent() throws Exception {
    when(indexSetRegistry.getDefault()).thenReturn(indexSet);
    when(streamService.load("000000000000000000000001")).thenThrow(NotFoundException.class);
    final ArgumentCaptor<StreamsChangedEvent> argumentCaptor = ArgumentCaptor.forClass(StreamsChangedEvent.class);
    migration.upgrade();
    verify(clusterEventBus).post(argumentCaptor.capture());
    final StreamsChangedEvent streamsChangedEvent = argumentCaptor.getValue();
    assertThat(streamsChangedEvent.streamIds()).containsOnly(Stream.DEFAULT_STREAM_ID);
}
Also used : StreamsChangedEvent(org.graylog2.streams.events.StreamsChangedEvent) Test(org.junit.Test)

Example 3 with ClusterEventBus

use of org.graylog2.events.ClusterEventBus in project graylog2-server by Graylog2.

the class V20161122174500_AssignIndexSetsToStreamsMigrationTest method upgrade.

@Test
public void upgrade() throws Exception {
    final Stream stream1 = mock(Stream.class);
    final Stream stream2 = mock(Stream.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSetService.findAll()).thenReturn(Collections.singletonList(indexSetConfig));
    when(indexSetConfig.id()).thenReturn("abc123");
    when(stream1.getId()).thenReturn("stream1");
    when(stream2.getId()).thenReturn("stream2");
    when(streamService.loadAll()).thenReturn(Lists.newArrayList(stream1, stream2));
    migration.upgrade();
    verify(stream1).setIndexSetId(indexSetConfig.id());
    verify(stream2).setIndexSetId(indexSetConfig.id());
    verify(streamService, times(1)).save(stream1);
    verify(streamService, times(1)).save(stream2);
    verify(clusterConfigService, times(1)).write(V20161122174500_AssignIndexSetsToStreamsMigration.MigrationCompleted.create(indexSetConfig.id(), Sets.newHashSet("stream1", "stream2"), Collections.emptySet()));
    verify(clusterEventBus, times(1)).post(StreamsChangedEvent.create(ImmutableSet.of("stream1", "stream2")));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 4 with ClusterEventBus

use of org.graylog2.events.ClusterEventBus in project graylog2-server by Graylog2.

the class V20161122174500_AssignIndexSetsToStreamsMigrationTest method upgradeWithAlreadyAssignedIndexSet.

@Test
public void upgradeWithAlreadyAssignedIndexSet() throws Exception {
    final Stream stream1 = mock(Stream.class);
    final Stream stream2 = mock(Stream.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSetService.findAll()).thenReturn(Collections.singletonList(indexSetConfig));
    when(indexSetConfig.id()).thenReturn("abc123");
    when(stream1.getId()).thenReturn("stream1");
    when(stream2.getId()).thenReturn("stream2");
    when(streamService.loadAll()).thenReturn(Lists.newArrayList(stream1, stream2));
    when(stream2.getIndexSetId()).thenReturn("abc123");
    migration.upgrade();
    verify(stream1).setIndexSetId(indexSetConfig.id());
    verify(stream2, never()).setIndexSetId(indexSetConfig.id());
    verify(streamService, times(1)).save(stream1);
    verify(streamService, never()).save(stream2);
    verify(clusterConfigService, times(1)).write(V20161122174500_AssignIndexSetsToStreamsMigration.MigrationCompleted.create(indexSetConfig.id(), Sets.newHashSet("stream1"), Collections.emptySet()));
    verify(clusterEventBus, times(1)).post(StreamsChangedEvent.create(ImmutableSet.of("stream1")));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 5 with ClusterEventBus

use of org.graylog2.events.ClusterEventBus in project graylog2-server by Graylog2.

the class V20161122174500_AssignIndexSetsToStreamsMigrationTest method upgradeWithFailedStreamUpdate.

@Test
public void upgradeWithFailedStreamUpdate() throws Exception {
    final Stream stream1 = mock(Stream.class);
    final Stream stream2 = mock(Stream.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSetService.findAll()).thenReturn(Collections.singletonList(indexSetConfig));
    when(indexSetConfig.id()).thenReturn("abc123");
    when(stream1.getId()).thenReturn("stream1");
    when(stream2.getId()).thenReturn("stream2");
    when(streamService.loadAll()).thenReturn(Lists.newArrayList(stream1, stream2));
    // Updating stream1 should fail!
    when(streamService.save(stream1)).thenThrow(ValidationException.class);
    migration.upgrade();
    verify(stream1).setIndexSetId(indexSetConfig.id());
    verify(stream2).setIndexSetId(indexSetConfig.id());
    verify(streamService, times(1)).save(stream1);
    verify(streamService, times(1)).save(stream2);
    // Check that the failed stream1 will be recorded as failed!
    verify(clusterConfigService, times(1)).write(V20161122174500_AssignIndexSetsToStreamsMigration.MigrationCompleted.create(indexSetConfig.id(), Sets.newHashSet("stream2"), Sets.newHashSet("stream1")));
    verify(clusterEventBus, times(1)).post(StreamsChangedEvent.create(ImmutableSet.of("stream2")));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)6 Before (org.junit.Before)6 ClusterEventBus (org.graylog2.events.ClusterEventBus)5 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)5 Stream (org.graylog2.plugin.streams.Stream)4 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 DBCollection (com.mongodb.DBCollection)2 DBObject (com.mongodb.DBObject)2 MongoJackObjectMapperProvider (org.graylog2.bindings.providers.MongoJackObjectMapperProvider)2 StreamsChangedEvent (org.graylog2.streams.events.StreamsChangedEvent)2 DebugEvent (org.graylog2.system.debug.DebugEvent)2 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 List (java.util.List)1 WidgetUpdatedEvent (org.graylog2.dashboards.widgets.events.WidgetUpdatedEvent)1 MongoConnection (org.graylog2.database.MongoConnection)1 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)1 IndexSetCreatedEvent (org.graylog2.indexer.indexset.events.IndexSetCreatedEvent)1