Search in sources :

Example 1 with SystemJobManager

use of org.graylog2.system.jobs.SystemJobManager in project graylog2-server by Graylog2.

the class MongoIndexSetTest method cycleSetsOldIndexToReadOnly.

@Test
public void cycleSetsOldIndexToReadOnly() throws SystemJobConcurrencyException {
    final String newIndexName = "graylog_1";
    final String oldIndexName = "graylog_0";
    final Map<String, Set<String>> indexNameAliases = ImmutableMap.of(oldIndexName, Collections.singleton("graylog_deflector"));
    when(indices.getIndexNamesAndAliases(anyString())).thenReturn(indexNameAliases);
    when(indices.create(newIndexName, mongoIndexSet)).thenReturn(true);
    when(indices.waitForRecovery(newIndexName)).thenReturn(ClusterHealthStatus.GREEN);
    final SetIndexReadOnlyAndCalculateRangeJob rangeJob = mock(SetIndexReadOnlyAndCalculateRangeJob.class);
    when(jobFactory.create(oldIndexName)).thenReturn(rangeJob);
    final MongoIndexSet mongoIndexSet = new MongoIndexSet(config, indices, nodeId, indexRangeService, auditEventSender, systemJobManager, jobFactory, activityWriter);
    mongoIndexSet.cycle();
    verify(jobFactory, times(1)).create(oldIndexName);
    verify(systemJobManager, times(1)).submitWithDelay(rangeJob, 30L, TimeUnit.SECONDS);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) SetIndexReadOnlyAndCalculateRangeJob(org.graylog2.indexer.indices.jobs.SetIndexReadOnlyAndCalculateRangeJob) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with SystemJobManager

use of org.graylog2.system.jobs.SystemJobManager in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method deleteDefaultIndexSet.

@Test
public void deleteDefaultIndexSet() throws Exception {
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetRegistry.getDefault()).thenReturn(indexSet);
    when(indexSetRegistry.get("id")).thenReturn(Optional.of(indexSet));
    when(indexSetCleanupJobFactory.create(indexSet)).thenReturn(mock(IndexSetCleanupJob.class));
    when(indexSetService.delete("id")).thenReturn(1);
    expectedException.expect(BadRequestException.class);
    indexSetsResource.delete("id", false);
    indexSetsResource.delete("id", true);
    verify(indexSetService, never()).delete("id");
    verify(systemJobManager, never()).submit(any(IndexSetCleanupJob.class));
    verifyNoMoreInteractions(indexSetService);
}
Also used : IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 3 with SystemJobManager

use of org.graylog2.system.jobs.SystemJobManager in project graylog2-server by Graylog2.

the class IndexSetsResourceTest method delete.

@Test
public void delete() throws Exception {
    final IndexSet indexSet = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
    when(indexSet.getConfig()).thenReturn(indexSetConfig);
    when(indexSetRegistry.get("id")).thenReturn(Optional.of(indexSet));
    when(indexSetCleanupJobFactory.create(indexSet)).thenReturn(mock(IndexSetCleanupJob.class));
    when(indexSetRegistry.getDefault()).thenReturn(null);
    when(indexSetService.delete("id")).thenReturn(1);
    indexSetsResource.delete("id", false);
    indexSetsResource.delete("id", true);
    verify(indexSetRegistry, times(2)).getDefault();
    verify(indexSetService, times(2)).delete("id");
    verify(systemJobManager, times(1)).submit(any(IndexSetCleanupJob.class));
    verifyNoMoreInteractions(indexSetService);
}
Also used : IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 IndexSet (org.graylog2.indexer.IndexSet)2 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)2 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)2 IndexSetCleanupJob (org.graylog2.indexer.indices.jobs.IndexSetCleanupJob)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Set (java.util.Set)1 SetIndexReadOnlyAndCalculateRangeJob (org.graylog2.indexer.indices.jobs.SetIndexReadOnlyAndCalculateRangeJob)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1