Search in sources :

Example 51 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig 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 52 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig 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 53 with IndexSetConfig

use of org.graylog2.indexer.indexset.IndexSetConfig 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)

Example 54 with IndexSetConfig

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

the class IndexSetsResourceTest method delete0.

@Test
public void delete0() throws Exception {
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetRegistry.getDefault()).thenReturn(null);
    when(indexSetRegistry.get("id")).thenReturn(Optional.of(indexSet));
    when(indexSetService.delete("id")).thenReturn(0);
    expectedException.expect(NotFoundException.class);
    expectedException.expectMessage("Couldn't delete index set with ID <id>");
    try {
        indexSetsResource.delete("id", false);
    } finally {
        verify(indexSetRegistry, times(1)).getDefault();
        verify(indexSetService, times(1)).delete("id");
        verifyNoMoreInteractions(indexSetService);
    }
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 55 with IndexSetConfig

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

the class IndexSetsResourceTest method setDefaultMakesIndexDefaultIfWritable.

@Test
public void setDefaultMakesIndexDefaultIfWritable() throws Exception {
    final String indexSetId = "newDefaultIndexSetId";
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = IndexSetConfig.create(indexSetId, "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", "index-template", 1, false);
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetService.get(indexSetId)).thenReturn(Optional.of(indexSetConfig));
    indexSetsResource.setDefault(indexSetId);
    final ArgumentCaptor<DefaultIndexSetConfig> defaultIndexSetIdCaptor = ArgumentCaptor.forClass(DefaultIndexSetConfig.class);
    verify(clusterConfigService, times(1)).write(defaultIndexSetIdCaptor.capture());
    final DefaultIndexSetConfig defaultIndexSetConfig = defaultIndexSetIdCaptor.getValue();
    assertThat(defaultIndexSetConfig).isNotNull();
    assertThat(defaultIndexSetConfig.defaultIndexSetId()).isEqualTo(indexSetId);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Aggregations

IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)53 Test (org.junit.Test)39 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)21 IndexSet (org.graylog2.indexer.IndexSet)11 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)10 MessageCountRotationStrategy (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy)10 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)8 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 IndexSetSummary (org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary)5 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 ClientErrorException (javax.ws.rs.ClientErrorException)4 NotFoundException (javax.ws.rs.NotFoundException)4 PUT (javax.ws.rs.PUT)4 Path (javax.ws.rs.Path)4 IndexSetService (org.graylog2.indexer.indexset.IndexSetService)4 IndexSetCleanupJob (org.graylog2.indexer.indices.jobs.IndexSetCleanupJob)4