Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for index being available when calculating index range #2098

Merged
merged 1 commit into from Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -115,8 +115,9 @@ public SortedSet<IndexRange> findAll() {

@Override
public IndexRange calculateRange(String index) {
final Stopwatch sw = Stopwatch.createStarted();
indices.waitForRecovery(index);
final DateTime now = DateTime.now(DateTimeZone.UTC);
final Stopwatch sw = Stopwatch.createStarted();
final TimestampStats stats = indices.timestampStatsOfIndex(index);
final int duration = Ints.saturatedCast(sw.stop().elapsed(TimeUnit.MILLISECONDS));

Expand Down
Expand Up @@ -23,6 +23,8 @@
import com.lordofthejars.nosqlunit.mongodb.InMemoryMongoDb;
import org.assertj.jodatime.api.Assertions;
import org.bson.types.ObjectId;
import org.elasticsearch.ElasticsearchTimeoutException;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.index.IndexNotFoundException;
import org.graylog2.bindings.providers.MongoJackObjectMapperProvider;
import org.graylog2.database.MongoConnectionRule;
Expand Down Expand Up @@ -167,6 +169,14 @@ public void calculateRangeReturnsIndexRange() throws Exception {
Assertions.assertThat(indexRange.calculatedAt()).isEqualToIgnoringHours(DateTime.now(DateTimeZone.UTC));
}

@Test(expected = ElasticsearchTimeoutException.class)
public void calculateRangeFailsIfIndexIsNotHealthy() throws Exception {
final String index = "graylog";
when(indices.waitForRecovery(index)).thenThrow(new ElasticsearchTimeoutException("TEST"));

indexRangeService.calculateRange(index);
}

@Test
@UsingDataSet(locations = "MongoIndexRangeServiceTest-EmptyCollection.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testCalculateRangeWithEmptyIndex() throws Exception {
Expand Down Expand Up @@ -262,4 +272,4 @@ public void testHandleIndexReopening() throws Exception {
assertThat(indexRanges.first().begin()).isEqualTo(begin);
assertThat(indexRanges.first().end()).isEqualTo(end);
}
}
}