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

Enable IndexActionTests and WatcherIndexingListenerTests #38738

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ private static long of(final int year, final int month) {
* @return {@link ZonedDateTime} instance for the current date-time with milliseconds precision in UTC
*/
public static ZonedDateTime nowWithMillisResolution() {
Clock millisResolutionClock = Clock.tick(Clock.systemUTC(), Duration.ofMillis(1));
return nowWithMillisResolution(Clock.systemUTC());
}

public static ZonedDateTime nowWithMillisResolution(Clock clock) {
Clock millisResolutionClock = Clock.tick(clock, Duration.ofMillis(1));
return ZonedDateTime.now(millisResolutionClock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.IOException;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
Expand Down Expand Up @@ -101,7 +102,7 @@ void setConfiguration(Configuration configuration) {
@Override
public Engine.Index preIndex(ShardId shardId, Engine.Index operation) {
if (isWatchDocument(shardId.getIndexName(), operation.type())) {
ZonedDateTime now = clock.instant().atZone(ZoneOffset.UTC);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was modified in #38514 . possibly in a merge conflict

ZonedDateTime now = Instant.ofEpochMilli(clock.millis()).atZone(ZoneOffset.UTC);
try {
Watch watch = parser.parseWithSecrets(operation.id(), true, operation.source(), now, XContentType.JSON,
operation.getIfSeqNo(), operation.getIfPrimaryTerm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.time.DateUtils;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.shard.ShardId;
Expand All @@ -41,7 +42,6 @@
import org.junit.Before;

import java.io.IOException;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.BitSet;
Expand Down Expand Up @@ -126,7 +126,6 @@ public void testPreIndexCheckActive() throws Exception {
verifyZeroInteractions(parser);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/38581")
public void testPreIndex() throws Exception {
when(operation.type()).thenReturn(Watch.DOC_TYPE);
when(operation.id()).thenReturn(randomAlphaOfLength(10));
Expand All @@ -140,8 +139,7 @@ public void testPreIndex() throws Exception {

Engine.Index returnedOperation = listener.preIndex(shardId, operation);
assertThat(returnedOperation, is(operation));

ZonedDateTime now = clock.instant().atZone(ZoneOffset.UTC);
ZonedDateTime now = DateUtils.nowWithMillisResolution(clock);
verify(parser).parseWithSecrets(eq(operation.id()), eq(true), eq(BytesArray.EMPTY), eq(now), anyObject(), anyLong(), anyLong());

if (isNewWatch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.xpack.core.watcher.actions.Action;
import org.elasticsearch.xpack.core.watcher.actions.Action.Result.Status;
import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource;
import org.elasticsearch.xpack.core.watcher.watch.Payload;
import org.elasticsearch.xpack.watcher.test.WatcherTestUtils;
Expand All @@ -37,7 +38,6 @@

import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -277,7 +277,6 @@ public void testConfigureIndexInMapAndAction() {
fieldName + "] or [ctx.payload._doc." + fieldName + "]"));
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/38581")
public void testIndexActionExecuteSingleDoc() throws Exception {
boolean customId = randomBoolean();
boolean docIdAsParam = customId && randomBoolean();
Expand Down Expand Up @@ -327,9 +326,8 @@ public void testIndexActionExecuteSingleDoc() throws Exception {
assertThat(indexRequest.getRefreshPolicy(), is(expectedRefreshPolicy));

if (timestampField != null) {
final DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
assertThat(indexRequest.sourceAsMap().keySet(), is(hasSize(2)));
assertThat(indexRequest.sourceAsMap(), hasEntry(timestampField, formatter.format(executionTime)));
assertThat(indexRequest.sourceAsMap(), hasEntry(timestampField, WatcherDateTimeUtils.formatDate(executionTime)));
} else {
assertThat(indexRequest.sourceAsMap().keySet(), is(hasSize(1)));
}
Expand Down