Search in sources :

Example 1 with StreamService

use of org.graylog2.streams.StreamService in project graylog2-server by Graylog2.

the class SearchesTest method setUp.

@Before
public void setUp() throws Exception {
    when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(INDEX_RANGES);
    metricRegistry = new MetricRegistry();
    searches = new Searches(new Configuration(), indexRangeService, client, metricRegistry, streamService, mock(Indices.class));
}
Also used : Configuration(org.graylog2.Configuration) MetricRegistry(com.codahale.metrics.MetricRegistry) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) Before(org.junit.Before)

Example 2 with StreamService

use of org.graylog2.streams.StreamService in project graylog2-server by Graylog2.

the class V20161125142400_EmailAlarmCallbackMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    final User localAdmin = mock(User.class);
    when(localAdmin.getId()).thenReturn(localAdminId);
    when(userService.getAdminUser()).thenReturn(localAdmin);
    this.emailAlarmCallbackMigrationPeriodical = new V20161125142400_EmailAlarmCallbackMigration(clusterConfigService, streamService, alarmCallbackConfigurationService, emailAlarmCallback, userService);
}
Also used : User(org.graylog2.plugin.database.users.User) Before(org.junit.Before)

Example 3 with StreamService

use of org.graylog2.streams.StreamService 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 StreamService

use of org.graylog2.streams.StreamService 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 StreamService

use of org.graylog2.streams.StreamService 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

Stream (org.graylog2.plugin.streams.Stream)5 Test (org.junit.Test)5 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)4 Before (org.junit.Before)4 MetricRegistry (com.codahale.metrics.MetricRegistry)1 DB (com.mongodb.DB)1 ZonedDateTime (java.time.ZonedDateTime)1 Configuration (org.graylog2.Configuration)1 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)1 MongoConnection (org.graylog2.database.MongoConnection)1 ClusterEventBus (org.graylog2.events.ClusterEventBus)1 User (org.graylog2.plugin.database.users.User)1 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)1 StreamsChangedEvent (org.graylog2.streams.events.StreamsChangedEvent)1 DateTime (org.joda.time.DateTime)1