-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for RebuildIndexRangesJob#calculateRange()
- Loading branch information
Jochen Schalanda
committed
Jun 3, 2015
1 parent
8b255be
commit 7be542e
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
graylog2-server/src/test/java/org/graylog2/indexer/ranges/RebuildIndexRangesJobTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* This file is part of Graylog. | ||
* | ||
* Graylog is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog2.indexer.ranges; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
import com.google.common.primitives.Ints; | ||
import com.lordofthejars.nosqlunit.annotation.UsingDataSet; | ||
import com.lordofthejars.nosqlunit.core.LoadStrategyEnum; | ||
import com.lordofthejars.nosqlunit.elasticsearch.ElasticsearchRule; | ||
import com.lordofthejars.nosqlunit.elasticsearch.EmbeddedElasticsearch; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.indices.IndexMissingException; | ||
import org.graylog2.Configuration; | ||
import org.graylog2.indexer.Deflector; | ||
import org.graylog2.indexer.EmptyIndexException; | ||
import org.graylog2.indexer.searches.Searches; | ||
import org.graylog2.shared.system.activities.NullActivityWriter; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.DateTimeZone; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import javax.inject.Inject; | ||
import java.util.Map; | ||
|
||
import static com.lordofthejars.nosqlunit.elasticsearch.ElasticsearchRule.ElasticsearchRuleBuilder.newElasticsearchRule; | ||
import static com.lordofthejars.nosqlunit.elasticsearch.EmbeddedElasticsearch.EmbeddedElasticsearchRuleBuilder.newEmbeddedElasticsearchRule; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class RebuildIndexRangesJobTest { | ||
@ClassRule | ||
public static final EmbeddedElasticsearch EMBEDDED_ELASTICSEARCH = newEmbeddedElasticsearchRule().build(); | ||
@Rule | ||
public ElasticsearchRule elasticsearchRule = newElasticsearchRule().defaultEmbeddedElasticsearch(); | ||
|
||
@Mock | ||
private Deflector deflector; | ||
@Inject | ||
private Client client; | ||
@Mock | ||
private IndexRangeService indexRangeService; | ||
private RebuildIndexRangesJob rebuildIndexRangesJob; | ||
|
||
|
||
@Before | ||
public void setUp() throws Exception { | ||
final MetricRegistry metricRegistry = new MetricRegistry(); | ||
final Searches searches = new Searches(new Configuration(), deflector, indexRangeService, client, metricRegistry); | ||
rebuildIndexRangesJob = new RebuildIndexRangesJob(deflector, searches, new NullActivityWriter(), indexRangeService); | ||
} | ||
|
||
@Test | ||
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT) | ||
public void testCalculateRange() throws Exception { | ||
final Map<String, Object> range = rebuildIndexRangesJob.calculateRange("graylog"); | ||
|
||
assertThat(range).isNotNull(); | ||
assertThat(range.get("index")).isEqualTo("graylog"); | ||
assertThat(range.get("start")).isEqualTo(Ints.saturatedCast(new DateTime(2015, 1, 1, 12, 0, DateTimeZone.UTC).getMillis() / 1000L)); | ||
} | ||
|
||
@Test(expected = IndexMissingException.class) | ||
public void testCalculateRangeWithNonExistingIndex() throws Exception { | ||
rebuildIndexRangesJob.calculateRange("does-not-exist"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...log2-server/src/test/resources/org/graylog2/indexer/ranges/RebuildIndexRangesJobTest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"documents": [ | ||
{ | ||
"document": [ | ||
{ | ||
"index": { | ||
"indexName": "graylog", | ||
"indexType": "message", | ||
"indexId": "0" | ||
} | ||
}, | ||
{ | ||
"data": { | ||
"source": "example.org", | ||
"message": "Hi", | ||
"timestamp": "2015-01-01 00:00:00.000" | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"document": [ | ||
{ | ||
"index": { | ||
"indexName": "graylog", | ||
"indexType": "message", | ||
"indexId": "1" | ||
} | ||
}, | ||
{ | ||
"data": { | ||
"source": "example.org", | ||
"message": "Ho", | ||
"timestamp": "2015-01-01 12:00:00.000", | ||
"n": 1 | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |