Skip to content

Commit

Permalink
More timestamp testing
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Mar 6, 2024
1 parent 8a3e37c commit c0c878e
Showing 1 changed file with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.opensearch.flowframework.common.CommonValue.WORKFLOW_ID;

public class FlowFrameworkBackwardsCompatibilityIT extends OpenSearchRestTestCase {

private static final ClusterType CLUSTER_TYPE = ClusterType.parse(System.getProperty("tests.rest.bwcsuite"));
Expand Down Expand Up @@ -115,18 +116,35 @@ public void testBackwardsCompatibility() throws Exception {
// mapping for 2.12 does not include time stamps
assertNull(t.createdTime());
assertNull(t.lastUpdatedTime());
assertNull(t.lastProvisionedTime());
break;
case MIXED:
assertTrue(pluginNames.contains("opensearch-flow-framework"));
// Time stamps may or may not be null depending on whether index has been accessed by new version node
// So just test that the template parses
assertEquals("test", t.name());
assertNull(t.lastProvisionedTime());
break;
case UPGRADED:
assertTrue(pluginNames.contains("opensearch-flow-framework"));
// mapping for 2.13+ includes time stamps
assertNotNull(t.createdTime());
assertNotNull(t.lastUpdatedTime());
Instant createdTime = t.createdTime();
Instant lastUpdatedTime = t.lastUpdatedTime();
assertNotNull(createdTime);
assertEquals(createdTime, lastUpdatedTime);
assertNull(t.lastProvisionedTime());

updateNoopTemplate(workflowId);
t = getTemplate(workflowId);
assertEquals(createdTime, t.createdTime());
assertTrue(t.lastUpdatedTime().isAfter(lastUpdatedTime));
lastUpdatedTime = t.lastUpdatedTime();
assertNull(t.lastProvisionedTime());

provisionNoopTemplate(workflowId);
t = getTemplate(workflowId);
assertEquals(createdTime, t.createdTime());
assertEquals(lastUpdatedTime, t.lastUpdatedTime());
assertTrue(t.lastProvisionedTime().isAfter(lastUpdatedTime));
break;
}
break;
Expand Down Expand Up @@ -164,10 +182,44 @@ private String createNoopTemplate() throws IOException, ParseException {
);
assertEquals(RestStatus.CREATED.getStatus(), response.getStatusLine().getStatusCode());

Pattern p = Pattern.compile("\"workflow_id\"\\s*:\\s*\"([^\"]+)\"");
Matcher m = p.matcher(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
assertTrue(m.find());
return m.group(1);
Map<String, Object> responseMap = entityAsMap(response);
String workflowId = (String) responseMap.get(WORKFLOW_ID);
assertNotNull(workflowId);
return workflowId;
}

private String updateNoopTemplate(String workflowId) throws IOException, ParseException {
Response response = TestHelpers.makeRequest(
client(),
"PUT",
"_plugins/_flow_framework/workflow/" + workflowId,
null,
"{\"name\":\"test2\", \"workflows\":{\"provision\": {\"nodes\": [{\"id\":\"test-step\", \"type\":\"noop\"}]}}}",
List.of(new BasicHeader(HttpHeaders.USER_AGENT, ""))
);
assertEquals(RestStatus.CREATED.getStatus(), response.getStatusLine().getStatusCode());

Map<String, Object> responseMap = entityAsMap(response);
String responseWorkflowId = (String) responseMap.get(WORKFLOW_ID);
assertEquals(workflowId, responseWorkflowId);
return responseWorkflowId;
}

private String provisionNoopTemplate(String workflowId) throws IOException, ParseException {
Response response = TestHelpers.makeRequest(
client(),
"POST",
"_plugins/_flow_framework/workflow/" + workflowId + "/_provision",
null,
"",
List.of(new BasicHeader(HttpHeaders.USER_AGENT, ""))
);
assertEquals(RestStatus.OK.getStatus(), response.getStatusLine().getStatusCode());

Map<String, Object> responseMap = entityAsMap(response);
String responseWorkflowId = (String) responseMap.get(WORKFLOW_ID);
assertEquals(workflowId, responseWorkflowId);
return responseWorkflowId;
}

private Template getTemplate(String workflowId) throws IOException, ParseException {
Expand Down

0 comments on commit c0c878e

Please sign in to comment.