Skip to content

Commit

Permalink
Change the default value of lastUpdateTime from the current timestamp…
Browse files Browse the repository at this point in the history
… to null (opendistro-for-elasticsearch#77)

1. Change the default value of lastUpdateTime from the current timestamp to null. Before the change, creating a detector returns one lastUpdateTime, while getting a detector returns a different lastUpdateTime. The difference is confusing to the user, and they may wonder what has happened between the creating and getting detector calls. After the change, creating a detector returns no last update time, while getting a detector returns a last update time.
2. Replace the mocked threadpool in 2 tests with a real threadpool object.

Testing done:
1. verified lastUpdateTime change in a cluster
2. gradle build
  • Loading branch information
kaituo committed Apr 13, 2020
1 parent f9d506e commit ed40113
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static AnomalyDetector parse(
List<Feature> features = new ArrayList<>();
int schemaVersion = 0;
Map<String, Object> uiMetadata = null;
Instant lastUpdateTime = Instant.now();
Instant lastUpdateTime = null;

ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation);
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ public void testParseAnomalyDetectorWithEmptyUiMetadata() throws IOException {
assertEquals("Parsing anomaly detector doesn't work", detector, parsedDetector);
}

public void testParseAnomalyDetectorWithNullLastUpdateTime() throws IOException {
AnomalyDetector detector = TestHelpers.randomAnomalyDetector(ImmutableMap.of(), null);
String detectorString = TestHelpers.xContentBuilderToString(detector.toXContent(TestHelpers.builder(), ToXContent.EMPTY_PARAMS));
AnomalyDetector parsedDetector = AnomalyDetector.parse(TestHelpers.parser(detectorString), detector.getDetectorId());
assertEquals("Parsing anomaly detector doesn't work", detector, parsedDetector);
assertEquals("Parsing anomaly detector doesn't work", detector.getDetectorId(), parsedDetector.getDetectorId());
assertNull(detector.getLastUpdateTime());
assertNotNull(parsedDetector.getLastUpdateTime());
}

public void testNullDetectorName() throws Exception {
TestHelpers
.assertFailWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void setUp() throws Exception {
.build();
clock = mock(Clock.class);
duration = Duration.ofHours(1);
context = TestHelpers.createThreadPool();
throttler = new Throttler(clock);

stateManager = new ADStateManager(client, xContentRegistry(), modelManager, settings, clientUtil, clock, duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.Before;
import org.junit.Test;

import com.amazon.opendistroforelasticsearch.ad.TestHelpers;
import java.time.Clock;

import static org.mockito.Mockito.mock;
Expand All @@ -36,8 +37,8 @@ public void setup() {
Client client = client();
Clock clock = mock(Clock.class);
Throttler throttler = new Throttler(clock);
ThreadPool threadPool = mock(ThreadPool.class);
clientUtil = new ClientUtil(Settings.EMPTY, client, throttler, threadPool);
ThreadPool context = TestHelpers.createThreadPool();
clientUtil = new ClientUtil(Settings.EMPTY, client, throttler, context);
}

@Test
Expand Down

0 comments on commit ed40113

Please sign in to comment.