use of org.opensearch.Build in project OpenSearch by opensearch-project.
the class MainResponseTests method createServerTestInstance.
@Override
protected org.opensearch.action.main.MainResponse createServerTestInstance(XContentType xContentType) {
String clusterUuid = randomAlphaOfLength(10);
ClusterName clusterName = new ClusterName(randomAlphaOfLength(10));
String nodeName = randomAlphaOfLength(10);
final String date = new Date(randomNonNegativeLong()).toString();
Version version = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, Version.CURRENT);
Build build = new Build(Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(), version.toString(), version.before(Version.V_1_0_0) ? null : "opensearch");
return new org.opensearch.action.main.MainResponse(nodeName, version, clusterName, clusterUuid, build);
}
use of org.opensearch.Build in project OpenSearch by opensearch-project.
the class MainResponseTests method createTestInstance.
@Override
protected MainResponse createTestInstance() {
String clusterUuid = randomAlphaOfLength(10);
ClusterName clusterName = new ClusterName(randomAlphaOfLength(10));
String nodeName = randomAlphaOfLength(10);
final String date = new Date(randomNonNegativeLong()).toString();
Version version = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, Version.CURRENT);
Build build = new Build(Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(), version.toString(), version.onOrAfter(Version.V_1_0_0) ? randomAlphaOfLength(10) : "");
return new MainResponse(nodeName, version, clusterName, clusterUuid, build);
}
use of org.opensearch.Build in project OpenSearch by opensearch-project.
the class RestMainActionTests method testGetResponse.
public void testGetResponse() throws Exception {
final String nodeName = "node1";
final ClusterName clusterName = new ClusterName("cluster1");
final String clusterUUID = randomAlphaOfLengthBetween(10, 20);
final Version version = Version.CURRENT;
final Build build = Build.CURRENT;
final boolean prettyPrint = randomBoolean();
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build);
XContentBuilder builder = JsonXContent.contentBuilder();
Map<String, String> params = new HashMap<>();
if (prettyPrint == false) {
params.put("pretty", String.valueOf(prettyPrint));
}
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();
BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
assertNotNull(response);
assertThat(response.status(), equalTo(RestStatus.OK));
assertThat(response.content().length(), greaterThan(0));
XContentBuilder responseBuilder = JsonXContent.contentBuilder();
if (prettyPrint) {
// do this to mimic what the rest layer does
responseBuilder.prettyPrint().lfAtEnd();
}
mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS);
BytesReference xcontentBytes = BytesReference.bytes(responseBuilder);
assertEquals(xcontentBytes, response.content());
}
use of org.opensearch.Build in project OpenSearch by opensearch-project.
the class MainResponseTests method mutateInstance.
@Override
protected MainResponse mutateInstance(MainResponse mutateInstance) {
String clusterUuid = mutateInstance.getClusterUuid();
Build build = mutateInstance.getBuild();
Version version = mutateInstance.getVersion();
String nodeName = mutateInstance.getNodeName();
ClusterName clusterName = mutateInstance.getClusterName();
switch(randomIntBetween(0, 4)) {
case 0:
clusterUuid = clusterUuid + randomAlphaOfLength(5);
break;
case 1:
nodeName = nodeName + randomAlphaOfLength(5);
break;
case 2:
// toggle the snapshot flag of the original Build parameter
build = new Build(Build.Type.UNKNOWN, build.hash(), build.date(), !build.isSnapshot(), build.getQualifiedVersion(), build.getDistribution());
break;
case 3:
version = randomValueOtherThan(version, () -> VersionUtils.randomVersion(random()));
break;
case 4:
clusterName = new ClusterName(clusterName + randomAlphaOfLength(5));
break;
}
return new MainResponse(nodeName, version, clusterName, clusterUuid, build);
}
use of org.opensearch.Build in project OpenSearch by opensearch-project.
the class MainResponseTests method testToXContent.
public void testToXContent() throws IOException {
String clusterUUID = randomAlphaOfLengthBetween(10, 20);
final Build current = Build.CURRENT;
Build build = new Build(current.type(), current.hash(), current.date(), current.isSnapshot(), current.getQualifiedVersion(), current.getDistribution());
Version version = Version.CURRENT;
MainResponse response = new MainResponse("nodeName", version, new ClusterName("clusterName"), clusterUUID, build);
XContentBuilder builder = XContentFactory.jsonBuilder();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertEquals("{" + "\"name\":\"nodeName\"," + "\"cluster_name\":\"clusterName\"," + "\"cluster_uuid\":\"" + clusterUUID + "\"," + "\"version\":{" + "\"distribution\":\"" + build.getDistribution() + "\"," + "\"number\":\"" + build.getQualifiedVersion() + "\"," + "\"build_type\":\"" + current.type().displayName() + "\"," + "\"build_hash\":\"" + current.hash() + "\"," + "\"build_date\":\"" + current.date() + "\"," + "\"build_snapshot\":" + current.isSnapshot() + "," + "\"lucene_version\":\"" + version.luceneVersion.toString() + "\"," + "\"minimum_wire_compatibility_version\":\"" + version.minimumCompatibilityVersion().toString() + "\"," + "\"minimum_index_compatibility_version\":\"" + version.minimumIndexCompatibilityVersion().toString() + "\"}," + "\"tagline\":\"" + TAGLINE + "\"" + "}", Strings.toString(builder));
}
Aggregations