Skip to content

Commit

Permalink
Fix index creation in RebuildIndexRangesJobTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Schalanda committed Jun 3, 2015
1 parent 577af65 commit c744e2a
Showing 1 changed file with 10 additions and 3 deletions.
Expand Up @@ -27,6 +27,7 @@
import org.graylog2.indexer.Deflector;
import org.graylog2.indexer.EmptyIndexException;
import org.graylog2.indexer.searches.Searches;
import org.graylog2.indexer.searches.SearchesTest;
import org.graylog2.shared.system.activities.NullActivityWriter;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
Expand All @@ -39,6 +40,7 @@
import org.mockito.runners.MockitoJUnitRunner;

import javax.inject.Inject;
import java.util.Collections;
import java.util.Map;

import static com.lordofthejars.nosqlunit.elasticsearch.ElasticsearchRule.ElasticsearchRuleBuilder.newElasticsearchRule;
Expand All @@ -47,10 +49,11 @@

@RunWith(MockitoJUnitRunner.class)
public class RebuildIndexRangesJobTest {
private static final String INDEX_NAME = "graylog";
@ClassRule
public static final EmbeddedElasticsearch EMBEDDED_ELASTICSEARCH = newEmbeddedElasticsearchRule().build();
@Rule
public ElasticsearchRule elasticsearchRule = newElasticsearchRule().defaultEmbeddedElasticsearch();
public ElasticsearchRule elasticsearchRule;

@Mock
private Deflector deflector;
Expand All @@ -60,6 +63,10 @@ public class RebuildIndexRangesJobTest {
private IndexRangeService indexRangeService;
private RebuildIndexRangesJob rebuildIndexRangesJob;

public RebuildIndexRangesJobTest() {
this.elasticsearchRule = newElasticsearchRule().defaultEmbeddedElasticsearch();
this.elasticsearchRule.setLoadStrategyFactory(new SearchesTest.IndexCreatingLoadStrategyFactory(Collections.singleton(INDEX_NAME)));
}

@Before
public void setUp() throws Exception {
Expand All @@ -71,10 +78,10 @@ public void setUp() throws Exception {
@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testCalculateRange() throws Exception {
final Map<String, Object> range = rebuildIndexRangesJob.calculateRange("graylog");
final Map<String, Object> range = rebuildIndexRangesJob.calculateRange(INDEX_NAME);

assertThat(range).isNotNull();
assertThat(range.get("index")).isEqualTo("graylog");
assertThat(range.get("index")).isEqualTo(INDEX_NAME);
assertThat(range.get("start")).isEqualTo(Ints.saturatedCast(new DateTime(2015, 1, 1, 12, 0, DateTimeZone.UTC).getMillis() / 1000L));
}

Expand Down

0 comments on commit c744e2a

Please sign in to comment.