Search in sources :

Example 16 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class MongoIndexSetRegistryTest method indexSetsCacheShouldBeInvalidatedForIndexSetDeletion.

@Test
public void indexSetsCacheShouldBeInvalidatedForIndexSetDeletion() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    final List<IndexSetConfig> result = this.indexSetsCache.get();
    assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    this.indexSetsCache.handleIndexSetDeletion(mock(IndexSetDeletedEvent.class));
    final IndexSetConfig newIndexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> newIndexSetConfigs = Collections.singletonList(newIndexSetConfig);
    when(indexSetService.findAll()).thenReturn(newIndexSetConfigs);
    final List<IndexSetConfig> newResult = this.indexSetsCache.get();
    assertThat(newResult).isNotNull().hasSize(1).containsExactly(newIndexSetConfig);
    verify(indexSetService, times(2)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) IndexSetDeletedEvent(org.graylog2.indexer.indexset.events.IndexSetDeletedEvent) Test(org.junit.Test)

Example 17 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class MongoIndexSetRegistryTest method getAllShouldNotBeCachedForCallAfterInvalidate.

@Test
public void getAllShouldNotBeCachedForCallAfterInvalidate() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    final MongoIndexSet indexSet = mock(MongoIndexSet.class);
    when(mongoIndexSetFactory.create(indexSetConfig)).thenReturn(indexSet);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
    this.indexSetsCache.invalidate();
    assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
    verify(indexSetService, times(2)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 18 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class MongoIndexSetRegistryTest method indexSetsCacheShouldReturnNewListAfterInvalidate.

@Test
public void indexSetsCacheShouldReturnNewListAfterInvalidate() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    final List<IndexSetConfig> result = this.indexSetsCache.get();
    assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    this.indexSetsCache.invalidate();
    final IndexSetConfig newIndexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> newIndexSetConfigs = Collections.singletonList(newIndexSetConfig);
    when(indexSetService.findAll()).thenReturn(newIndexSetConfigs);
    final List<IndexSetConfig> newResult = this.indexSetsCache.get();
    assertThat(newResult).isNotNull().hasSize(1).containsExactly(newIndexSetConfig);
    verify(indexSetService, times(2)).findAll();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 19 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class MongoIndexSetRegistryTest method indexSetsCacheShouldBeInvalidatedForIndexSetCreation.

@Test
public void indexSetsCacheShouldBeInvalidatedForIndexSetCreation() {
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
    when(indexSetService.findAll()).thenReturn(indexSetConfigs);
    final List<IndexSetConfig> result = this.indexSetsCache.get();
    assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
    this.indexSetsCache.handleIndexSetCreation(mock(IndexSetCreatedEvent.class));
    final IndexSetConfig newIndexSetConfig = mock(IndexSetConfig.class);
    final List<IndexSetConfig> newIndexSetConfigs = Collections.singletonList(newIndexSetConfig);
    when(indexSetService.findAll()).thenReturn(newIndexSetConfigs);
    final List<IndexSetConfig> newResult = this.indexSetsCache.get();
    assertThat(newResult).isNotNull().hasSize(1).containsExactly(newIndexSetConfig);
    verify(indexSetService, times(2)).findAll();
}
Also used : IndexSetCreatedEvent(org.graylog2.indexer.indexset.events.IndexSetCreatedEvent) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Test(org.junit.Test)

Example 20 with IndexSetService

use of org.graylog2.indexer.indexset.IndexSetService in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method save.

@Test
public void save() {
    final IndexSetConfig indexSetConfig = IndexSetConfig.create("title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "prefix-template", 1, false);
    final IndexSetConfig savedIndexSetConfig = indexSetConfig.toBuilder().id("id").build();
    when(indexSetService.save(indexSetConfig)).thenReturn(savedIndexSetConfig);
    final IndexSetSummary summary = indexSetsResource.save(IndexSetSummary.fromIndexSetConfig(indexSetConfig, false));
    verify(indexSetService, times(1)).save(indexSetConfig);
    verify(indexSetService, times(1)).getDefault();
    verifyNoMoreInteractions(indexSetService);
    assertThat(summary.toIndexSetConfig()).isEqualTo(savedIndexSetConfig);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)24 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)12 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)8 MessageCountRotationStrategy (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy)8 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)6 RotationStrategyConfig (org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)6 DeletionRetentionStrategyConfig (org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig)5 MessageCountRotationStrategyConfig (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig)5 IndexSet (org.graylog2.indexer.IndexSet)3 IndexSetResponse (org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse)3 IndexSetSummary (org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary)3 IndexSetCreatedEvent (org.graylog2.indexer.indexset.events.IndexSetCreatedEvent)2 IndexSetCleanupJob (org.graylog2.indexer.indices.jobs.IndexSetCleanupJob)2 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)1 ClusterEventBus (org.graylog2.events.ClusterEventBus)1 IndexSetDeletedEvent (org.graylog2.indexer.indexset.events.IndexSetDeletedEvent)1 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1