Deprecate AbstractHlrc* and AbstractHlrcStreamable* base test classes (#41014)

* moved hlrc parsing tests from xpack to hlrc module and removed dependency on hlrc from xpack core

* deprecated old base test class

* added deprecated jdoc tag

* split test between xpack-core part and hlrc part

* added lang-mustache test dependency, this previously came in via
hlrc dependency.

* added hlrc dependency on a qa module

* duplicated ClusterPrivilegeName class in xpack-core, since x-pack
core no longer has a dependency on hlrc.

* replace ClusterPrivilegeName usages with string literals

* moved tests to dedicated to hlrc packages in order to remove Hlrc part from the name and make sure to use imports instead of full qualified class where possible

* remove ESTestCase. from method invocation and use method directly,
because these tests indirectly extend from ESTestCase
This commit is contained in:
Martijn van Groningen 2019-04-10 14:06:06 +02:00
parent 64a05e522f
commit 1eff8976a8
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
32 changed files with 1058 additions and 664 deletions

View File

@ -1,9 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol;
package org.elasticsearch.client;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.ToXContent;
@ -14,6 +27,11 @@ import java.io.IOException;
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;
/**
* @deprecated Use {@link AbstractResponseTestCase} instead of this class.
*/
// TODO: Remove and change subclasses to use AbstractResponseTestCase instead
@Deprecated
public abstract class AbstractHlrcStreamableXContentTestCase<T extends ToXContent & Streamable, H>
extends AbstractStreamableXContentTestCase<T> {

View File

@ -1,9 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol;
package org.elasticsearch.client;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
@ -11,6 +24,11 @@ import org.elasticsearch.test.AbstractXContentTestCase;
import java.io.IOException;
/**
* @deprecated Use {@link AbstractResponseTestCase} instead of this class.
*/
// TODO: Remove and change subclasses to use AbstractResponseTestCase instead
@Deprecated
public abstract class AbstractHlrcXContentTestCase<T extends ToXContent, H> extends AbstractXContentTestCase<T> {
/**

View File

@ -1,13 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack;
package org.elasticsearch.client;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
import org.elasticsearch.protocol.xpack.XPackInfoResponse.BuildInfo;
import org.elasticsearch.protocol.xpack.XPackInfoResponse.LicenseInfo;
import org.elasticsearch.protocol.xpack.XPackInfoResponse.FeatureSetsInfo;

View File

@ -1,19 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.xpack.core.dataframe.transforms.hlrc;
package org.elasticsearch.client.dataframe.transforms.hlrc;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcXContentTestCase;
import org.elasticsearch.client.AbstractHlrcXContentTestCase;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStats;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStatsTests;
import java.io.IOException;
public class DataFrameIndexerTransformStatsHlrcTests extends AbstractHlrcXContentTestCase<
public class DataFrameIndexerTransformStatsTests extends AbstractHlrcXContentTestCase<
DataFrameIndexerTransformStats,
org.elasticsearch.client.dataframe.transforms.DataFrameIndexerTransformStats> {
@ -38,7 +50,7 @@ public class DataFrameIndexerTransformStatsHlrcTests extends AbstractHlrcXConten
@Override
protected DataFrameIndexerTransformStats createTestInstance() {
return DataFrameIndexerTransformStatsTests.randomStats(DataFrameIndexerTransformStats.DEFAULT_TRANSFORM_ID);
return DataFrameTransformStateTests.randomStats(DataFrameIndexerTransformStats.DEFAULT_TRANSFORM_ID);
}
@Override

View File

@ -1,19 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.xpack.core.dataframe.transforms.hlrc;
package org.elasticsearch.client.dataframe.transforms.hlrc;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcXContentTestCase;
import org.elasticsearch.client.AbstractHlrcXContentTestCase;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointStats;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointStatsTests;
import java.io.IOException;
public class DataFrameTransformCheckpointStatsHlrcTests extends AbstractHlrcXContentTestCase<
public class DataFrameTransformCheckpointStatsTests extends AbstractHlrcXContentTestCase<
DataFrameTransformCheckpointStats,
org.elasticsearch.client.dataframe.transforms.DataFrameTransformCheckpointStats> {
@ -36,7 +48,7 @@ public class DataFrameTransformCheckpointStatsHlrcTests extends AbstractHlrcXCon
@Override
protected DataFrameTransformCheckpointStats createTestInstance() {
return DataFrameTransformCheckpointStatsTests.randomDataFrameTransformCheckpointStats();
return DataFrameTransformStateTests.randomDataFrameTransformCheckpointStats();
}
@Override

View File

@ -1,27 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.xpack.core.dataframe.transforms.hlrc;
package org.elasticsearch.client.dataframe.transforms.hlrc;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcXContentTestCase;
import org.elasticsearch.client.AbstractHlrcXContentTestCase;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointingInfo;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointingInfoTests;
import java.io.IOException;
public class DataFrameTransformCheckpointingInfoHlrcTests extends AbstractHlrcXContentTestCase<
public class DataFrameTransformCheckpointingInfoTests extends AbstractHlrcXContentTestCase<
DataFrameTransformCheckpointingInfo,
org.elasticsearch.client.dataframe.transforms.DataFrameTransformCheckpointingInfo> {
public static DataFrameTransformCheckpointingInfo fromHlrc(
org.elasticsearch.client.dataframe.transforms.DataFrameTransformCheckpointingInfo instance) {
return new DataFrameTransformCheckpointingInfo(
DataFrameTransformCheckpointStatsHlrcTests.fromHlrc(instance.getCurrent()),
DataFrameTransformCheckpointStatsHlrcTests.fromHlrc(instance.getInProgress()),
DataFrameTransformCheckpointStatsTests.fromHlrc(instance.getCurrent()),
DataFrameTransformCheckpointStatsTests.fromHlrc(instance.getInProgress()),
instance.getOperationsBehind());
}
@ -39,7 +51,7 @@ public class DataFrameTransformCheckpointingInfoHlrcTests extends AbstractHlrcX
@Override
protected DataFrameTransformCheckpointingInfo createTestInstance() {
return DataFrameTransformCheckpointingInfoTests.randomDataFrameTransformCheckpointingInfo();
return DataFrameTransformStateTests.randomDataFrameTransformCheckpointingInfo();
}
@Override
@ -52,4 +64,4 @@ public class DataFrameTransformCheckpointingInfoHlrcTests extends AbstractHlrcX
return true;
}
}
}

View File

@ -1,21 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.xpack.core.dataframe.transforms.hlrc;
package org.elasticsearch.client.dataframe.transforms.hlrc;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcXContentTestCase;
import org.elasticsearch.client.AbstractHlrcXContentTestCase;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStats;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStats;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStatsTests;
import java.io.IOException;
import java.util.function.Predicate;
public class DataFrameTransformStateAndStatsHlrcTests extends AbstractHlrcXContentTestCase<DataFrameTransformStateAndStats,
public class DataFrameTransformStateAndStatsTests extends AbstractHlrcXContentTestCase<DataFrameTransformStateAndStats,
org.elasticsearch.client.dataframe.transforms.DataFrameTransformStateAndStats> {
@Override
@ -28,15 +40,15 @@ public class DataFrameTransformStateAndStatsHlrcTests extends AbstractHlrcXConte
public DataFrameTransformStateAndStats convertHlrcToInternal(
org.elasticsearch.client.dataframe.transforms.DataFrameTransformStateAndStats instance) {
return new DataFrameTransformStateAndStats(instance.getId(),
DataFrameTransformStateHlrcTests.fromHlrc(instance.getTransformState()),
DataFrameIndexerTransformStatsHlrcTests.fromHlrc(instance.getTransformStats()),
DataFrameTransformCheckpointingInfoHlrcTests.fromHlrc(instance.getCheckpointingInfo()));
DataFrameTransformStateTests.fromHlrc(instance.getTransformState()),
DataFrameIndexerTransformStatsTests.fromHlrc(instance.getTransformStats()),
DataFrameTransformCheckpointingInfoTests.fromHlrc(instance.getCheckpointingInfo()));
}
@Override
protected DataFrameTransformStateAndStats createTestInstance() {
// the transform id is not part of HLRC as it's only to a field for internal storage, therefore use a default id
return DataFrameTransformStateAndStatsTests
return DataFrameTransformStateTests
.randomDataFrameTransformStateAndStats(DataFrameIndexerTransformStats.DEFAULT_TRANSFORM_ID);
}

View File

@ -0,0 +1,125 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.dataframe.transforms.hlrc;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.client.AbstractHlrcXContentTestCase;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameIndexerTransformStats;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointStats;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformCheckpointingInfo;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformState;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStats;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformTaskState;
import org.elasticsearch.xpack.core.indexing.IndexerState;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
public class DataFrameTransformStateTests extends AbstractHlrcXContentTestCase<DataFrameTransformState,
org.elasticsearch.client.dataframe.transforms.DataFrameTransformState> {
public static DataFrameTransformState fromHlrc(org.elasticsearch.client.dataframe.transforms.DataFrameTransformState instance) {
return new DataFrameTransformState(DataFrameTransformTaskState.fromString(instance.getTaskState().value()),
IndexerState.fromString(instance.getIndexerState().value()), instance.getPosition(), instance.getCheckpoint(),
instance.getReason());
}
@Override
public org.elasticsearch.client.dataframe.transforms.DataFrameTransformState doHlrcParseInstance(XContentParser parser)
throws IOException {
return org.elasticsearch.client.dataframe.transforms.DataFrameTransformState.fromXContent(parser);
}
@Override
public DataFrameTransformState convertHlrcToInternal(org.elasticsearch.client.dataframe.transforms.DataFrameTransformState instance) {
return fromHlrc(instance);
}
@Override
protected DataFrameTransformState createTestInstance() {
return randomDataFrameTransformState();
}
@Override
protected DataFrameTransformState doParseInstance(XContentParser parser) throws IOException {
return DataFrameTransformState.fromXContent(parser);
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
protected Predicate<String> getRandomFieldsExcludeFilter() {
return field -> field.equals("current_position");
}
public static DataFrameTransformStateAndStats randomDataFrameTransformStateAndStats(String id) {
return new DataFrameTransformStateAndStats(id,
randomDataFrameTransformState(),
randomStats(id),
randomDataFrameTransformCheckpointingInfo());
}
public static DataFrameTransformCheckpointingInfo randomDataFrameTransformCheckpointingInfo() {
return new DataFrameTransformCheckpointingInfo(randomDataFrameTransformCheckpointStats(),
randomDataFrameTransformCheckpointStats(), randomNonNegativeLong());
}
public static DataFrameTransformCheckpointStats randomDataFrameTransformCheckpointStats() {
return new DataFrameTransformCheckpointStats(randomNonNegativeLong(), randomNonNegativeLong());
}
public static DataFrameIndexerTransformStats randomStats(String transformId) {
return new DataFrameIndexerTransformStats(transformId, randomLongBetween(10L, 10000L),
randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L),
randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L),
randomLongBetween(0L, 10000L));
}
public static DataFrameTransformState randomDataFrameTransformState() {
return new DataFrameTransformState(randomFrom(DataFrameTransformTaskState.values()),
randomFrom(IndexerState.values()),
randomPosition(),
randomLongBetween(0,10),
randomBoolean() ? null : randomAlphaOfLength(10));
}
private static Map<String, Object> randomPosition() {
if (randomBoolean()) {
return null;
}
int numFields = randomIntBetween(1, 5);
Map<String, Object> position = new HashMap<>();
for (int i = 0; i < numFields; i++) {
Object value;
if (randomBoolean()) {
value = randomLong();
} else {
value = randomAlphaOfLengthBetween(1, 10);
}
position.put(randomAlphaOfLengthBetween(3, 10), value);
}
return position;
}
}

View File

@ -0,0 +1,222 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.graph.hlrc;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.client.graph.Connection;
import org.elasticsearch.client.graph.GraphExploreResponse;
import org.elasticsearch.client.graph.Vertex;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.client.AbstractHlrcXContentTestCase;
import org.elasticsearch.protocol.xpack.graph.Connection.ConnectionId;
import org.elasticsearch.test.AbstractXContentTestCase;
import org.junit.Assert;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import static org.hamcrest.Matchers.equalTo;
public class GraphExploreResponseTests extends AbstractHlrcXContentTestCase<
org.elasticsearch.protocol.xpack.graph.GraphExploreResponse,
GraphExploreResponse> {
static final Function<Vertex.VertexId, org.elasticsearch.protocol.xpack.graph.Vertex.VertexId> VERTEX_ID_FUNCTION =
vId -> new org.elasticsearch.protocol.xpack.graph.Vertex.VertexId(vId.getField(), vId.getTerm());
static final Function<Vertex, org.elasticsearch.protocol.xpack.graph.Vertex> VERTEX_FUNCTION =
v -> new org.elasticsearch.protocol.xpack.graph.Vertex(v.getField(), v.getTerm(), v.getWeight(),
v.getHopDepth(), v.getBg(), v.getFg());
@Override
public GraphExploreResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return GraphExploreResponse.fromXContent(parser);
}
@Override
public org.elasticsearch.protocol.xpack.graph.GraphExploreResponse convertHlrcToInternal(GraphExploreResponse instance) {
return new org.elasticsearch.protocol.xpack.graph.GraphExploreResponse(instance.getTookInMillis(), instance.isTimedOut(),
instance.getShardFailures(), convertVertices(instance), convertConnections(instance), instance.isReturnDetailedInfo());
}
public Map<org.elasticsearch.protocol.xpack.graph.Vertex.VertexId, org.elasticsearch.protocol.xpack.graph.Vertex> convertVertices(
GraphExploreResponse instance) {
final Collection<Vertex.VertexId> vertexIds = instance.getVertexIds();
final Map<org.elasticsearch.protocol.xpack.graph.Vertex.VertexId, org.elasticsearch.protocol.xpack.graph.Vertex> vertexMap =
new LinkedHashMap<>(vertexIds.size());
for (Vertex.VertexId vertexId : vertexIds) {
final Vertex vertex = instance.getVertex(vertexId);
vertexMap.put(VERTEX_ID_FUNCTION.apply(vertexId), VERTEX_FUNCTION.apply(vertex));
}
return vertexMap;
}
public Map<ConnectionId, org.elasticsearch.protocol.xpack.graph.Connection> convertConnections(GraphExploreResponse instance) {
final Collection<Connection.ConnectionId> connectionIds = instance.getConnectionIds();
final Map<ConnectionId,org.elasticsearch.protocol.xpack.graph.Connection> connectionMap= new LinkedHashMap<>(connectionIds.size());
for (Connection.ConnectionId connectionId : connectionIds) {
final Connection connection = instance.getConnection(connectionId);
final ConnectionId connectionId1 = new ConnectionId(VERTEX_ID_FUNCTION.apply(connectionId.getSource()),
VERTEX_ID_FUNCTION.apply(connectionId.getTarget()));
final org.elasticsearch.protocol.xpack.graph.Connection connection1 = new org.elasticsearch.protocol.xpack.graph.Connection(
VERTEX_FUNCTION.apply(connection.getFrom()), VERTEX_FUNCTION.apply(connection.getTo()), connection.getWeight(),
connection.getDocCount());
connectionMap.put(connectionId1, connection1);
}
return connectionMap;
}
@Override
protected org.elasticsearch.protocol.xpack.graph.GraphExploreResponse createTestInstance() {
return createInstance(0);
}
private static org.elasticsearch.protocol.xpack.graph.GraphExploreResponse createInstance(int numFailures) {
int numItems = randomIntBetween(4, 128);
boolean timedOut = randomBoolean();
boolean showDetails = randomBoolean();
long overallTookInMillis = randomNonNegativeLong();
Map<org.elasticsearch.protocol.xpack.graph.Vertex.VertexId, org.elasticsearch.protocol.xpack.graph.Vertex> vertices =
new HashMap<>();
Map<ConnectionId,
org.elasticsearch.protocol.xpack.graph.Connection> connections = new HashMap<>();
ShardOperationFailedException [] failures = new ShardOperationFailedException [numFailures];
for (int i = 0; i < failures.length; i++) {
failures[i] = new ShardSearchFailure(new ElasticsearchException("an error"));
}
//Create random set of vertices
for (int i = 0; i < numItems; i++) {
org.elasticsearch.protocol.xpack.graph.Vertex v = new org.elasticsearch.protocol.xpack.graph.Vertex("field1",
randomAlphaOfLength(5), randomDouble(), 0,
showDetails? randomIntBetween(100, 200):0,
showDetails? randomIntBetween(1, 100):0);
vertices.put(v.getId(), v);
}
//Wire up half the vertices randomly
org.elasticsearch.protocol.xpack.graph.Vertex[] vs =
vertices.values().toArray(new org.elasticsearch.protocol.xpack.graph.Vertex[vertices.size()]);
for (int i = 0; i < numItems/2; i++) {
org.elasticsearch.protocol.xpack.graph.Vertex v1 = vs[randomIntBetween(0, vs.length-1)];
org.elasticsearch.protocol.xpack.graph.Vertex v2 = vs[randomIntBetween(0, vs.length-1)];
if(v1 != v2) {
org.elasticsearch.protocol.xpack.graph.Connection conn = new org.elasticsearch.protocol.xpack.graph.Connection(v1, v2,
randomDouble(), randomLongBetween(1, 10));
connections.put(conn.getId(), conn);
}
}
return new org.elasticsearch.protocol.xpack.graph.GraphExploreResponse(overallTookInMillis, timedOut, failures,
vertices, connections, showDetails);
}
private static org.elasticsearch.protocol.xpack.graph.GraphExploreResponse createTestInstanceWithFailures() {
return createInstance(randomIntBetween(1, 128));
}
@Override
protected org.elasticsearch.protocol.xpack.graph.GraphExploreResponse doParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.protocol.xpack.graph.GraphExploreResponse.fromXContent(parser);
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
protected boolean assertToXContentEquivalence() {
return false;
}
@Override
protected String[] getShuffleFieldsExceptions() {
return new String[]{"vertices", "connections"};
}
protected Predicate<String> getRandomFieldsExcludeFilterWhenResultHasErrors() {
return field -> field.startsWith("responses");
}
@Override
protected void assertEqualInstances(org.elasticsearch.protocol.xpack.graph.GraphExploreResponse expectedInstance,
org.elasticsearch.protocol.xpack.graph.GraphExploreResponse newInstance) {
Assert.assertThat(newInstance.getTook(), equalTo(expectedInstance.getTook()));
Assert.assertThat(newInstance.isTimedOut(), equalTo(expectedInstance.isTimedOut()));
Comparator<org.elasticsearch.protocol.xpack.graph.Connection> connComparator =
Comparator.comparing(o -> o.getId().toString());
org.elasticsearch.protocol.xpack.graph.Connection[] newConns =
newInstance.getConnections().toArray(new org.elasticsearch.protocol.xpack.graph.Connection[0]);
org.elasticsearch.protocol.xpack.graph.Connection[] expectedConns =
expectedInstance.getConnections().toArray(new org.elasticsearch.protocol.xpack.graph.Connection[0]);
Arrays.sort(newConns, connComparator);
Arrays.sort(expectedConns, connComparator);
Assert.assertArrayEquals(expectedConns, newConns);
//Sort the vertices lists before equality test (map insertion sequences can cause order differences)
Comparator<org.elasticsearch.protocol.xpack.graph.Vertex> comparator = Comparator.comparing(o -> o.getId().toString());
org.elasticsearch.protocol.xpack.graph.Vertex[] newVertices =
newInstance.getVertices().toArray(new org.elasticsearch.protocol.xpack.graph.Vertex[0]);
org.elasticsearch.protocol.xpack.graph.Vertex[] expectedVertices =
expectedInstance.getVertices().toArray(new org.elasticsearch.protocol.xpack.graph.Vertex[0]);
Arrays.sort(newVertices, comparator);
Arrays.sort(expectedVertices, comparator);
Assert.assertArrayEquals(expectedVertices, newVertices);
ShardOperationFailedException[] newFailures = newInstance.getShardFailures();
ShardOperationFailedException[] expectedFailures = expectedInstance.getShardFailures();
Assert.assertEquals(expectedFailures.length, newFailures.length);
}
/**
* Test parsing {@link org.elasticsearch.protocol.xpack.graph.GraphExploreResponse} with inner failures as they
* don't support asserting on xcontent equivalence, given exceptions are not parsed back as the same original class.
* We run the usual {@link AbstractXContentTestCase#testFromXContent()} without failures, and this other test with
* failures where we disable asserting on xcontent equivalence at the end.
*/
public void testFromXContentWithFailures() throws IOException {
Supplier<org.elasticsearch.protocol.xpack.graph.GraphExploreResponse> instanceSupplier =
GraphExploreResponseTests::createTestInstanceWithFailures;
//with random fields insertion in the inner exceptions, some random stuff may be parsed back as metadata,
//but that does not bother our assertions, as we only want to test that we don't break.
boolean supportsUnknownFields = true;
//exceptions are not of the same type whenever parsed back
boolean assertToXContentEquivalence = false;
AbstractXContentTestCase.testFromXContent(
AbstractXContentTestCase.NUMBER_OF_TEST_RUNS, instanceSupplier, supportsUnknownFields, getShuffleFieldsExceptions(),
getRandomFieldsExcludeFilterWhenResultHasErrors(), this::createParser, this::doParseInstance,
this::assertEqualInstances, assertToXContentEquivalence, ToXContent.EMPTY_PARAMS);
}
}

View File

@ -1,14 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.license;
package org.elasticsearch.client.license;
import org.elasticsearch.client.license.GetBasicStatusResponse;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
public class GetBasicStatusResponseTests
extends AbstractHlrcStreamableXContentTestCase<org.elasticsearch.license.GetBasicStatusResponse, GetBasicStatusResponse> {

View File

@ -1,13 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.license;
package org.elasticsearch.client.license;
import org.elasticsearch.client.license.GetTrialStatusResponse;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
public class GetTrialStatusResponseTests extends
AbstractHlrcStreamableXContentTestCase<org.elasticsearch.license.GetTrialStatusResponse, GetTrialStatusResponse> {

View File

@ -0,0 +1,38 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.license;
import org.elasticsearch.test.ESTestCase;
import static org.hamcrest.CoreMatchers.equalTo;
public class LicenseStatusTests extends ESTestCase {
public void testCompatibility() {
final LicenseStatus[] values = LicenseStatus.values();
final LicenseStatus[] hlrcValues = LicenseStatus.values();
assertThat(values.length, equalTo(hlrcValues.length));
for (LicenseStatus value : values) {
final LicenseStatus licenseStatus = LicenseStatus.fromString(value.label());
assertThat(licenseStatus.label(), equalTo(value.label()));
}
}
}

View File

@ -0,0 +1,140 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.license;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
public class PutLicenseResponseTests extends AbstractHlrcStreamableXContentTestCase<
org.elasticsearch.protocol.xpack.license.PutLicenseResponse, org.elasticsearch.client.license.PutLicenseResponse> {
@Override
public org.elasticsearch.client.license.PutLicenseResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.license.PutLicenseResponse.fromXContent(parser);
}
@Override
public org.elasticsearch.protocol.xpack.license.PutLicenseResponse convertHlrcToInternal(
org.elasticsearch.client.license.PutLicenseResponse instance) {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(instance.isAcknowledged(),
org.elasticsearch.protocol.xpack.license.LicensesStatus.valueOf(instance.status().name()),
instance.acknowledgeHeader(), instance.acknowledgeMessages());
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
protected Predicate<String> getRandomFieldsExcludeFilter() {
// The structure of the response is such that unknown fields inside acknowledge cannot be supported since they
// are treated as messages from new services
return p -> p.startsWith("acknowledge");
}
@Override
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createTestInstance() {
boolean acknowledged = randomBoolean();
org.elasticsearch.protocol.xpack.license.LicensesStatus status =
randomFrom(org.elasticsearch.protocol.xpack.license.LicensesStatus.VALID,
org.elasticsearch.protocol.xpack.license.LicensesStatus.INVALID,
org.elasticsearch.protocol.xpack.license.LicensesStatus.EXPIRED);
String messageHeader;
Map<String, String[]> ackMessages;
if (randomBoolean()) {
messageHeader = randomAlphaOfLength(10);
ackMessages = randomAckMessages();
} else {
messageHeader = null;
ackMessages = Collections.emptyMap();
}
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(acknowledged, status, messageHeader, ackMessages);
}
private static Map<String, String[]> randomAckMessages() {
int nFeatures = randomIntBetween(1, 5);
Map<String, String[]> ackMessages = new HashMap<>();
for (int i = 0; i < nFeatures; i++) {
String feature = randomAlphaOfLengthBetween(9, 15);
int nMessages = randomIntBetween(1, 5);
String[] messages = new String[nMessages];
for (int j = 0; j < nMessages; j++) {
messages[j] = randomAlphaOfLengthBetween(10, 30);
}
ackMessages.put(feature, messages);
}
return ackMessages;
}
@Override
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createBlankInstance() {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse();
}
@Override
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse mutateInstance(
org.elasticsearch.protocol.xpack.license.PutLicenseResponse response) {
@SuppressWarnings("unchecked")
Function<org.elasticsearch.protocol.xpack.license.PutLicenseResponse,
org.elasticsearch.protocol.xpack.license.PutLicenseResponse> mutator = randomFrom(
r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
r.isAcknowledged() == false,
r.status(),
r.acknowledgeHeader(),
r.acknowledgeMessages()),
r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
r.isAcknowledged(),
mutateStatus(r.status()),
r.acknowledgeHeader(),
r.acknowledgeMessages()),
r -> {
if (r.acknowledgeMessages().isEmpty()) {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
r.isAcknowledged(),
r.status(),
randomAlphaOfLength(10),
randomAckMessages()
);
} else {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(r.isAcknowledged(), r.status());
}
}
);
return mutator.apply(response);
}
private org.elasticsearch.protocol.xpack.license.LicensesStatus mutateStatus(
org.elasticsearch.protocol.xpack.license.LicensesStatus status) {
return randomValueOtherThan(status, () -> randomFrom(LicensesStatus.values()));
}
}

View File

@ -1,14 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.license;
package org.elasticsearch.client.license;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.license.PostStartBasicResponse;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
import java.io.IOException;
import java.util.Collections;

View File

@ -1,13 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.xpack.core.ml.action;
package org.elasticsearch.client.ml;
import org.elasticsearch.client.ml.MlInfoResponse;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.xpack.core.ml.action.MlInfoAction.Response;
import java.io.IOException;

View File

@ -0,0 +1,82 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.ml;
import com.carrotsearch.randomizedtesting.generators.CodepointSetGenerator;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.xpack.core.ml.action.PutCalendarAction;
import org.elasticsearch.xpack.core.ml.calendars.Calendar;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class PutCalendarActionResponseTests
extends AbstractHlrcStreamableXContentTestCase<PutCalendarAction.Response, PutCalendarResponse> {
@Override
protected PutCalendarAction.Response createTestInstance() {
return new PutCalendarAction.Response(testInstance());
}
@Override
protected PutCalendarAction.Response doParseInstance(XContentParser parser) throws IOException {
return new PutCalendarAction.Response(Calendar.LENIENT_PARSER.parse(parser, null).build());
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
public PutCalendarResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return PutCalendarResponse.fromXContent(parser);
}
@Override
public PutCalendarAction.Response convertHlrcToInternal(PutCalendarResponse instance) {
org.elasticsearch.client.ml.calendars.Calendar hlrcCalendar = instance.getCalendar();
Calendar internalCalendar = new Calendar(hlrcCalendar.getId(), hlrcCalendar.getJobIds(), hlrcCalendar.getDescription());
return new PutCalendarAction.Response(internalCalendar);
}
@Override
protected PutCalendarAction.Response createBlankInstance() {
return new PutCalendarAction.Response();
}
public static Calendar testInstance() {
return testInstance(new CodepointSetGenerator("abcdefghijklmnopqrstuvwxyz".toCharArray()).ofCodePointsLength(random(), 10, 10));
}
public static Calendar testInstance(String calendarId) {
int size = randomInt(10);
List<String> items = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
items.add(randomAlphaOfLengthBetween(1, 20));
}
String description = null;
if (randomBoolean()) {
description = randomAlphaOfLength(20);
}
return new Calendar(calendarId, items, description);
}
}

View File

@ -1,12 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.xpack.core.security.action.user;
package org.elasticsearch.client.security.hlrc;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.Version;
import org.elasticsearch.client.security.HasPrivilegesResponse;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
@ -16,10 +31,11 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.xpack.core.security.authz.permission.ResourcePrivileges;
import org.hamcrest.Matchers;
import org.junit.Assert;
import java.io.IOException;
import java.util.ArrayList;
@ -35,32 +51,36 @@ import java.util.stream.Collectors;
import static org.hamcrest.Matchers.equalTo;
public class HasPrivilegesResponseTests
extends AbstractHlrcStreamableXContentTestCase<HasPrivilegesResponse, org.elasticsearch.client.security.HasPrivilegesResponse> {
public class HasPrivilegesResponseTests extends AbstractHlrcStreamableXContentTestCase<
org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse,
HasPrivilegesResponse> {
public void testSerializationV64OrV65() throws IOException {
final HasPrivilegesResponse original = randomResponse();
final Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_4_0, Version.V_6_5_1);
final HasPrivilegesResponse copy = serializeAndDeserialize(original, version);
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse original = randomResponse();
final Version version = VersionUtils.randomVersionBetween(LuceneTestCase.random(), Version.V_6_4_0, Version.V_6_5_1);
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy = serializeAndDeserialize(original, version);
assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch()));
assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable());
assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges()));
assertThat(copy.getApplicationPrivileges(), equalTo(original.getApplicationPrivileges()));
Assert.assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch()));
Assert.assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable());
Assert.assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges()));
Assert.assertThat(copy.getApplicationPrivileges(), equalTo(original.getApplicationPrivileges()));
}
public void testSerializationV63() throws IOException {
final HasPrivilegesResponse original = randomResponse();
final HasPrivilegesResponse copy = serializeAndDeserialize(original, Version.V_6_3_0);
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse original = randomResponse();
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy =
serializeAndDeserialize(original, Version.V_6_3_0);
assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch()));
assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable());
assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges()));
assertThat(copy.getApplicationPrivileges(), equalTo(Collections.emptyMap()));
Assert.assertThat(copy.isCompleteMatch(), equalTo(original.isCompleteMatch()));
Assert.assertThat(copy.getClusterPrivileges().entrySet(), Matchers.emptyIterable());
Assert.assertThat(copy.getIndexPrivileges(), equalTo(original.getIndexPrivileges()));
Assert.assertThat(copy.getApplicationPrivileges(), equalTo(Collections.emptyMap()));
}
public void testToXContent() throws Exception {
final HasPrivilegesResponse response = new HasPrivilegesResponse("daredevil", false, Collections.singletonMap("manage", true),
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse response =
new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse("daredevil",
false, Collections.singletonMap("manage", true),
Arrays.asList(
ResourcePrivileges.builder("staff")
.addPrivileges(MapBuilder.<String, Boolean>newMapBuilder(new LinkedHashMap<>()).put("read", true)
@ -77,7 +97,7 @@ public class HasPrivilegesResponseTests
BytesReference bytes = BytesReference.bytes(builder);
final String json = bytes.utf8ToString();
assertThat(json, equalTo("{" +
Assert.assertThat(json, equalTo("{" +
"\"username\":\"daredevil\"," +
"\"has_all_requested\":false," +
"\"cluster\":{\"manage\":true}," +
@ -96,23 +116,23 @@ public class HasPrivilegesResponseTests
}
@Override
protected HasPrivilegesResponse createBlankInstance() {
return new HasPrivilegesResponse();
protected org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse createBlankInstance() {
return new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse();
}
@Override
protected HasPrivilegesResponse createTestInstance() {
protected org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse createTestInstance() {
return randomResponse();
}
@Override
public org.elasticsearch.client.security.HasPrivilegesResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.security.HasPrivilegesResponse.fromXContent(parser);
public HasPrivilegesResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return HasPrivilegesResponse.fromXContent(parser);
}
@Override
public HasPrivilegesResponse convertHlrcToInternal(org.elasticsearch.client.security.HasPrivilegesResponse hlrc) {
return new HasPrivilegesResponse(
public org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse convertHlrcToInternal(HasPrivilegesResponse hlrc) {
return new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse(
hlrc.getUsername(),
hlrc.hasAllRequested(),
hlrc.getClusterPrivileges(),
@ -128,21 +148,23 @@ public class HasPrivilegesResponseTests
.collect(Collectors.toList());
}
private HasPrivilegesResponse serializeAndDeserialize(HasPrivilegesResponse original, Version version) throws IOException {
private org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse serializeAndDeserialize(
org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse original, Version version) throws IOException {
logger.info("Test serialize/deserialize with version {}", version);
final BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(version);
original.writeTo(out);
final HasPrivilegesResponse copy = new HasPrivilegesResponse();
final org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse copy =
new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse();
final StreamInput in = out.bytes().streamInput();
in.setVersion(version);
copy.readFrom(in);
assertThat(in.read(), equalTo(-1));
Assert.assertThat(in.read(), equalTo(-1));
return copy;
}
private HasPrivilegesResponse randomResponse() {
private org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse randomResponse() {
final String username = randomAlphaOfLengthBetween(4, 12);
final Map<String, Boolean> cluster = new HashMap<>();
for (String priv : randomArray(1, 6, String[]::new, () -> randomAlphaOfLengthBetween(3, 12))) {
@ -150,16 +172,19 @@ public class HasPrivilegesResponseTests
}
final Collection<ResourcePrivileges> index = randomResourcePrivileges();
final Map<String, Collection<ResourcePrivileges>> application = new HashMap<>();
for (String app : randomArray(1, 3, String[]::new, () -> randomAlphaOfLengthBetween(3, 6).toLowerCase(Locale.ROOT))) {
for (String app : randomArray(1, 3, String[]::new,
() -> randomAlphaOfLengthBetween(3, 6).toLowerCase(Locale.ROOT))) {
application.put(app, randomResourcePrivileges());
}
return new HasPrivilegesResponse(username, randomBoolean(), cluster, index, application);
return new org.elasticsearch.xpack.core.security.action.user.HasPrivilegesResponse(username, randomBoolean(),
cluster, index, application);
}
private Collection<ResourcePrivileges> randomResourcePrivileges() {
final Collection<ResourcePrivileges> list = new ArrayList<>();
// Use hash set to force a unique set of resources
for (String resource : Sets.newHashSet(randomArray(1, 3, String[]::new, () -> randomAlphaOfLengthBetween(2, 6)))) {
for (String resource : Sets.newHashSet(randomArray(1, 3, String[]::new,
() -> randomAlphaOfLengthBetween(2, 6)))) {
final Map<String, Boolean> privileges = new HashMap<>();
for (String priv : randomArray(1, 5, String[]::new, () -> randomAlphaOfLengthBetween(3, 8))) {
privileges.put(priv, randomBoolean());

View File

@ -1,10 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.watcher;
package org.elasticsearch.client.watcher;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@ -14,7 +28,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.client.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.xpack.core.watcher.actions.ActionStatus;
import org.elasticsearch.xpack.core.watcher.execution.ExecutionState;
import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource;
@ -90,7 +104,7 @@ public class GetWatchResponseTests extends
@Override
protected GetWatchResponse createTestInstance() {
String id = randomAlphaOfLength(10);
if (rarely()) {
if (LuceneTestCase.rarely()) {
return new GetWatchResponse(id);
}
long version = randomLongBetween(0, 10);
@ -128,8 +142,8 @@ public class GetWatchResponseTests extends
long version = randomLongBetween(-1, Long.MAX_VALUE);
WatchStatus.State state = new WatchStatus.State(randomBoolean(), nowWithMillisResolution());
ExecutionState executionState = randomFrom(ExecutionState.values());
ZonedDateTime lastChecked = rarely() ? null : nowWithMillisResolution();
ZonedDateTime lastMetCondition = rarely() ? null : nowWithMillisResolution();
ZonedDateTime lastChecked = LuceneTestCase.rarely() ? null : nowWithMillisResolution();
ZonedDateTime lastMetCondition = LuceneTestCase.rarely() ? null : nowWithMillisResolution();
int size = randomIntBetween(0, 5);
Map<String, ActionStatus> actionMap = new HashMap<>();
for (int i = 0; i < size; i++) {

View File

@ -0,0 +1,58 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.watcher.hlrc;
import org.elasticsearch.client.watcher.DeleteWatchResponse;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.client.AbstractHlrcXContentTestCase;
import java.io.IOException;
public class DeleteWatchResponseTests extends AbstractHlrcXContentTestCase<
org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse, DeleteWatchResponse> {
@Override
protected org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse createTestInstance() {
String id = randomAlphaOfLength(10);
long version = randomLongBetween(1, 10);
boolean found = randomBoolean();
return new org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse(id, version, found);
}
@Override
protected org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse doParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse.fromXContent(parser);
}
@Override
public DeleteWatchResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return DeleteWatchResponse.fromXContent(parser);
}
@Override
public org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse convertHlrcToInternal(DeleteWatchResponse instance) {
return new org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse(instance.getId(), instance.getVersion(),
instance.isFound());
}
@Override
protected boolean supportsUnknownFields() {
return false;
}
}

View File

@ -1,17 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.watcher;
package org.elasticsearch.client.watcher.hlrc;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.protocol.AbstractHlrcXContentTestCase;
import org.elasticsearch.client.AbstractHlrcXContentTestCase;
import org.elasticsearch.xpack.core.watcher.transport.actions.execute.ExecuteWatchResponse;
import java.io.IOException;

View File

@ -0,0 +1,60 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.watcher.hlrc;
import org.elasticsearch.client.watcher.PutWatchResponse;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.client.AbstractHlrcXContentTestCase;
import java.io.IOException;
public class PutWatchResponseTests extends AbstractHlrcXContentTestCase<
org.elasticsearch.protocol.xpack.watcher.PutWatchResponse, PutWatchResponse> {
@Override
protected org.elasticsearch.protocol.xpack.watcher.PutWatchResponse createTestInstance() {
String id = randomAlphaOfLength(10);
long seqNo = randomNonNegativeLong();
long primaryTerm = randomLongBetween(1, 20);
long version = randomLongBetween(1, 10);
boolean created = randomBoolean();
return new org.elasticsearch.protocol.xpack.watcher.PutWatchResponse(id, version, seqNo, primaryTerm, created);
}
@Override
protected org.elasticsearch.protocol.xpack.watcher.PutWatchResponse doParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.protocol.xpack.watcher.PutWatchResponse.fromXContent(parser);
}
@Override
public PutWatchResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.watcher.PutWatchResponse.fromXContent(parser);
}
@Override
public org.elasticsearch.protocol.xpack.watcher.PutWatchResponse convertHlrcToInternal(PutWatchResponse instance) {
return new org.elasticsearch.protocol.xpack.watcher.PutWatchResponse(instance.getId(), instance.getVersion(),
instance.getSeqNo(), instance.getPrimaryTerm(), instance.isCreated());
}
@Override
protected boolean supportsUnknownFields() {
return false;
}
}

View File

@ -46,11 +46,11 @@ dependencies {
testCompile "org.slf4j:slf4j-api:${versions.slf4j}"
testCompile project(path: ':modules:reindex', configuration: 'runtime')
testCompile project(path: ':modules:parent-join', configuration: 'runtime')
testCompile project(path: ':modules:lang-mustache', configuration: 'runtime')
testCompile project(path: ':modules:analysis-common', configuration: 'runtime')
testCompile(project(':x-pack:license-tools')) {
transitive = false
}
testCompile ("org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}")
}
ext.expansions = [

View File

@ -1,197 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.protocol.xpack.graph;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcXContentTestCase;
import org.elasticsearch.test.AbstractXContentTestCase;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import static org.hamcrest.Matchers.equalTo;
public class GraphExploreResponseTests extends
AbstractHlrcXContentTestCase<GraphExploreResponse, org.elasticsearch.client.graph.GraphExploreResponse> {
static final Function<org.elasticsearch.client.graph.Vertex.VertexId, Vertex.VertexId> VERTEX_ID_FUNCTION =
vId -> new Vertex.VertexId(vId.getField(), vId.getTerm());
static final Function<org.elasticsearch.client.graph.Vertex, Vertex> VERTEX_FUNCTION =
v -> new Vertex(v.getField(), v.getTerm(), v.getWeight(), v.getHopDepth(), v.getBg(), v.getFg());
@Override
public org.elasticsearch.client.graph.GraphExploreResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.graph.GraphExploreResponse.fromXContent(parser);
}
@Override
public GraphExploreResponse convertHlrcToInternal(org.elasticsearch.client.graph.GraphExploreResponse instance) {
return new GraphExploreResponse(instance.getTookInMillis(), instance.isTimedOut(),
instance.getShardFailures(), convertVertices(instance), convertConnections(instance), instance.isReturnDetailedInfo());
}
public Map<Vertex.VertexId, Vertex> convertVertices(org.elasticsearch.client.graph.GraphExploreResponse instance) {
final Collection<org.elasticsearch.client.graph.Vertex.VertexId> vertexIds = instance.getVertexIds();
final Map<Vertex.VertexId, Vertex> vertexMap = new LinkedHashMap<>(vertexIds.size());
for (org.elasticsearch.client.graph.Vertex.VertexId vertexId : vertexIds) {
final org.elasticsearch.client.graph.Vertex vertex = instance.getVertex(vertexId);
vertexMap.put(VERTEX_ID_FUNCTION.apply(vertexId), VERTEX_FUNCTION.apply(vertex));
}
return vertexMap;
}
public Map<Connection.ConnectionId, Connection> convertConnections(org.elasticsearch.client.graph.GraphExploreResponse instance) {
final Collection<org.elasticsearch.client.graph.Connection.ConnectionId> connectionIds = instance.getConnectionIds();
final Map<Connection.ConnectionId, Connection> connectionMap = new LinkedHashMap<>(connectionIds.size());
for (org.elasticsearch.client.graph.Connection.ConnectionId connectionId : connectionIds) {
final org.elasticsearch.client.graph.Connection connection = instance.getConnection(connectionId);
final Connection.ConnectionId connectionId1 =
new Connection.ConnectionId(VERTEX_ID_FUNCTION.apply(connectionId.getSource()),
VERTEX_ID_FUNCTION.apply(connectionId.getTarget()));
final Connection connection1 = new Connection(VERTEX_FUNCTION.apply(connection.getFrom()),
VERTEX_FUNCTION.apply(connection.getTo()),
connection.getWeight(), connection.getDocCount());
connectionMap.put(connectionId1, connection1);
}
return connectionMap;
}
@Override
protected GraphExploreResponse createTestInstance() {
return createInstance(0);
}
private static GraphExploreResponse createInstance(int numFailures) {
int numItems = randomIntBetween(4, 128);
boolean timedOut = randomBoolean();
boolean showDetails = randomBoolean();
long overallTookInMillis = randomNonNegativeLong();
Map<Vertex.VertexId, Vertex> vertices = new HashMap<>();
Map<Connection.ConnectionId, Connection> connections = new HashMap<>();
ShardOperationFailedException [] failures = new ShardOperationFailedException [numFailures];
for (int i = 0; i < failures.length; i++) {
failures[i] = new ShardSearchFailure(new ElasticsearchException("an error"));
}
//Create random set of vertices
for (int i = 0; i < numItems; i++) {
Vertex v = new Vertex("field1", randomAlphaOfLength(5), randomDouble(), 0,
showDetails?randomIntBetween(100, 200):0,
showDetails?randomIntBetween(1, 100):0);
vertices.put(v.getId(), v);
}
//Wire up half the vertices randomly
Vertex[] vs = vertices.values().toArray(new Vertex[vertices.size()]);
for (int i = 0; i < numItems/2; i++) {
Vertex v1 = vs[randomIntBetween(0, vs.length-1)];
Vertex v2 = vs[randomIntBetween(0, vs.length-1)];
if(v1 != v2) {
Connection conn = new Connection(v1, v2, randomDouble(), randomLongBetween(1, 10));
connections.put(conn.getId(), conn);
}
}
return new GraphExploreResponse(overallTookInMillis, timedOut, failures, vertices, connections, showDetails);
}
private static GraphExploreResponse createTestInstanceWithFailures() {
return createInstance(randomIntBetween(1, 128));
}
@Override
protected GraphExploreResponse doParseInstance(XContentParser parser) throws IOException {
return GraphExploreResponse.fromXContent(parser);
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
protected boolean assertToXContentEquivalence() {
return false;
}
@Override
protected String[] getShuffleFieldsExceptions() {
return new String[]{"vertices", "connections"};
}
protected Predicate<String> getRandomFieldsExcludeFilterWhenResultHasErrors() {
return field -> field.startsWith("responses");
}
@Override
protected void assertEqualInstances( GraphExploreResponse expectedInstance, GraphExploreResponse newInstance) {
assertThat(newInstance.getTook(), equalTo(expectedInstance.getTook()));
assertThat(newInstance.isTimedOut(), equalTo(expectedInstance.isTimedOut()));
Comparator<Connection> connComparator = new Comparator<Connection>() {
@Override
public int compare(Connection o1, Connection o2) {
return o1.getId().toString().compareTo(o2.getId().toString());
}
};
Connection[] newConns = newInstance.getConnections().toArray(new Connection[0]);
Connection[] expectedConns = expectedInstance.getConnections().toArray(new Connection[0]);
Arrays.sort(newConns, connComparator);
Arrays.sort(expectedConns, connComparator);
assertArrayEquals(expectedConns, newConns);
//Sort the vertices lists before equality test (map insertion sequences can cause order differences)
Comparator<Vertex> comparator = new Comparator<Vertex>() {
@Override
public int compare(Vertex o1, Vertex o2) {
return o1.getId().toString().compareTo(o2.getId().toString());
}
};
Vertex[] newVertices = newInstance.getVertices().toArray(new Vertex[0]);
Vertex[] expectedVertices = expectedInstance.getVertices().toArray(new Vertex[0]);
Arrays.sort(newVertices, comparator);
Arrays.sort(expectedVertices, comparator);
assertArrayEquals(expectedVertices, newVertices);
ShardOperationFailedException[] newFailures = newInstance.getShardFailures();
ShardOperationFailedException[] expectedFailures = expectedInstance.getShardFailures();
assertEquals(expectedFailures.length, newFailures.length);
}
/**
* Test parsing {@link GraphExploreResponse} with inner failures as they don't support asserting on xcontent equivalence, given
* exceptions are not parsed back as the same original class. We run the usual {@link AbstractXContentTestCase#testFromXContent()}
* without failures, and this other test with failures where we disable asserting on xcontent equivalence at the end.
*/
public void testFromXContentWithFailures() throws IOException {
Supplier< GraphExploreResponse> instanceSupplier = GraphExploreResponseTests::createTestInstanceWithFailures;
//with random fields insertion in the inner exceptions, some random stuff may be parsed back as metadata,
//but that does not bother our assertions, as we only want to test that we don't break.
boolean supportsUnknownFields = true;
//exceptions are not of the same type whenever parsed back
boolean assertToXContentEquivalence = false;
AbstractXContentTestCase.testFromXContent(
NUMBER_OF_TEST_RUNS, instanceSupplier, supportsUnknownFields, getShuffleFieldsExceptions(),
getRandomFieldsExcludeFilterWhenResultHasErrors(), this::createParser, this::doParseInstance,
this::assertEqualInstances, assertToXContentEquivalence, ToXContent.EMPTY_PARAMS);
}
}

View File

@ -9,25 +9,10 @@ import java.io.IOException;
import org.elasticsearch.test.ESTestCase;
import static org.hamcrest.CoreMatchers.equalTo;
public class LicenseStatusTests extends ESTestCase {
public void testSerialization() throws IOException {
LicenseStatus status = randomFrom(LicenseStatus.values());
assertSame(status, copyWriteable(status, writableRegistry(), LicenseStatus::readFrom));
}
public void testCompatibility() {
final LicenseStatus[] values = LicenseStatus.values();
final org.elasticsearch.client.license.LicenseStatus[] hlrcValues =
org.elasticsearch.client.license.LicenseStatus.values();
assertThat(values.length, equalTo(hlrcValues.length));
for (LicenseStatus value : values) {
final org.elasticsearch.client.license.LicenseStatus licenseStatus =
org.elasticsearch.client.license.LicenseStatus.fromString(value.label());
assertThat(licenseStatus.label(), equalTo(value.label()));
}
}
}

View File

@ -1,118 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.protocol.xpack.license;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
public class PutLicenseResponseTests extends
AbstractHlrcStreamableXContentTestCase<PutLicenseResponse, org.elasticsearch.client.license.PutLicenseResponse> {
@Override
public org.elasticsearch.client.license.PutLicenseResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.license.PutLicenseResponse.fromXContent(parser);
}
@Override
public PutLicenseResponse convertHlrcToInternal(org.elasticsearch.client.license.PutLicenseResponse instance) {
return new PutLicenseResponse(instance.isAcknowledged(), LicensesStatus.valueOf(instance.status().name()),
instance.acknowledgeHeader(), instance.acknowledgeMessages());
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
protected Predicate<String> getRandomFieldsExcludeFilter() {
// The structure of the response is such that unknown fields inside acknowledge cannot be supported since they
// are treated as messages from new services
return p -> p.startsWith("acknowledge");
}
@Override
protected PutLicenseResponse createTestInstance() {
boolean acknowledged = randomBoolean();
LicensesStatus status = randomFrom(LicensesStatus.VALID, LicensesStatus.INVALID, LicensesStatus.EXPIRED);
String messageHeader;
Map<String, String[]> ackMessages;
if (randomBoolean()) {
messageHeader = randomAlphaOfLength(10);
ackMessages = randomAckMessages();
} else {
messageHeader = null;
ackMessages = Collections.emptyMap();
}
return new PutLicenseResponse(acknowledged, status, messageHeader, ackMessages);
}
private static Map<String, String[]> randomAckMessages() {
int nFeatures = randomIntBetween(1, 5);
Map<String, String[]> ackMessages = new HashMap<>();
for (int i = 0; i < nFeatures; i++) {
String feature = randomAlphaOfLengthBetween(9, 15);
int nMessages = randomIntBetween(1, 5);
String[] messages = new String[nMessages];
for (int j = 0; j < nMessages; j++) {
messages[j] = randomAlphaOfLengthBetween(10, 30);
}
ackMessages.put(feature, messages);
}
return ackMessages;
}
@Override
protected PutLicenseResponse createBlankInstance() {
return new PutLicenseResponse();
}
@Override
protected PutLicenseResponse mutateInstance(PutLicenseResponse response) {
@SuppressWarnings("unchecked")
Function<PutLicenseResponse, PutLicenseResponse> mutator = randomFrom(
r -> new PutLicenseResponse(
r.isAcknowledged() == false,
r.status(),
r.acknowledgeHeader(),
r.acknowledgeMessages()),
r -> new PutLicenseResponse(
r.isAcknowledged(),
mutateStatus(r.status()),
r.acknowledgeHeader(),
r.acknowledgeMessages()),
r -> {
if (r.acknowledgeMessages().isEmpty()) {
return new PutLicenseResponse(
r.isAcknowledged(),
r.status(),
randomAlphaOfLength(10),
randomAckMessages()
);
} else {
return new PutLicenseResponse(r.isAcknowledged(), r.status());
}
}
);
return mutator.apply(response);
}
private LicensesStatus mutateStatus(LicensesStatus status) {
return randomValueOtherThan(status, () -> randomFrom(LicensesStatus.values()));
}
}

View File

@ -1,43 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.protocol.xpack.watcher;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcXContentTestCase;
import java.io.IOException;
public class DeleteWatchResponseTests extends
AbstractHlrcXContentTestCase<DeleteWatchResponse, org.elasticsearch.client.watcher.DeleteWatchResponse> {
@Override
protected DeleteWatchResponse createTestInstance() {
String id = randomAlphaOfLength(10);
long version = randomLongBetween(1, 10);
boolean found = randomBoolean();
return new DeleteWatchResponse(id, version, found);
}
@Override
protected DeleteWatchResponse doParseInstance(XContentParser parser) throws IOException {
return DeleteWatchResponse.fromXContent(parser);
}
@Override
public org.elasticsearch.client.watcher.DeleteWatchResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.watcher.DeleteWatchResponse.fromXContent(parser);
}
@Override
public DeleteWatchResponse convertHlrcToInternal(org.elasticsearch.client.watcher.DeleteWatchResponse instance) {
return new DeleteWatchResponse(instance.getId(), instance.getVersion(), instance.isFound());
}
@Override
protected boolean supportsUnknownFields() {
return false;
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.protocol.xpack.watcher;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcXContentTestCase;
import java.io.IOException;
public class PutWatchResponseTests extends
AbstractHlrcXContentTestCase<PutWatchResponse, org.elasticsearch.client.watcher.PutWatchResponse> {
@Override
protected PutWatchResponse createTestInstance() {
String id = randomAlphaOfLength(10);
long seqNo = randomNonNegativeLong();
long primaryTerm = randomLongBetween(1, 20);
long version = randomLongBetween(1, 10);
boolean created = randomBoolean();
return new PutWatchResponse(id, version, seqNo, primaryTerm, created);
}
@Override
protected PutWatchResponse doParseInstance(XContentParser parser) throws IOException {
return PutWatchResponse.fromXContent(parser);
}
@Override
public org.elasticsearch.client.watcher.PutWatchResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.watcher.PutWatchResponse.fromXContent(parser);
}
@Override
public PutWatchResponse convertHlrcToInternal(org.elasticsearch.client.watcher.PutWatchResponse instance) {
return new PutWatchResponse(instance.getId(), instance.getVersion(), instance.getSeqNo(), instance.getPrimaryTerm(),
instance.isCreated());
}
@Override
protected boolean supportsUnknownFields() {
return false;
}
}

View File

@ -1,58 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.core.dataframe.transforms.hlrc;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcXContentTestCase;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformState;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateTests;
import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformTaskState;
import org.elasticsearch.xpack.core.indexing.IndexerState;
import java.io.IOException;
import java.util.function.Predicate;
public class DataFrameTransformStateHlrcTests extends AbstractHlrcXContentTestCase<DataFrameTransformState,
org.elasticsearch.client.dataframe.transforms.DataFrameTransformState> {
public static DataFrameTransformState fromHlrc(org.elasticsearch.client.dataframe.transforms.DataFrameTransformState instance) {
return new DataFrameTransformState(DataFrameTransformTaskState.fromString(instance.getTaskState().value()),
IndexerState.fromString(instance.getIndexerState().value()), instance.getPosition(), instance.getCheckpoint(),
instance.getReason());
}
@Override
public org.elasticsearch.client.dataframe.transforms.DataFrameTransformState doHlrcParseInstance(XContentParser parser)
throws IOException {
return org.elasticsearch.client.dataframe.transforms.DataFrameTransformState.fromXContent(parser);
}
@Override
public DataFrameTransformState convertHlrcToInternal(org.elasticsearch.client.dataframe.transforms.DataFrameTransformState instance) {
return fromHlrc(instance);
}
@Override
protected DataFrameTransformState createTestInstance() {
return DataFrameTransformStateTests.randomDataFrameTransformState();
}
@Override
protected DataFrameTransformState doParseInstance(XContentParser parser) throws IOException {
return DataFrameTransformState.fromXContent(parser);
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
protected Predicate<String> getRandomFieldsExcludeFilter() {
return field -> field.equals("current_position");
}
}

View File

@ -1,50 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.core.ml.action;
import org.elasticsearch.client.ml.PutCalendarResponse;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
import org.elasticsearch.xpack.core.ml.calendars.Calendar;
import org.elasticsearch.xpack.core.ml.calendars.CalendarTests;
import java.io.IOException;
public class PutCalendarActionResponseTests
extends AbstractHlrcStreamableXContentTestCase<PutCalendarAction.Response, PutCalendarResponse> {
@Override
protected PutCalendarAction.Response createTestInstance() {
return new PutCalendarAction.Response(CalendarTests.testInstance());
}
@Override
protected PutCalendarAction.Response doParseInstance(XContentParser parser) throws IOException {
return new PutCalendarAction.Response(Calendar.LENIENT_PARSER.parse(parser, null).build());
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
public PutCalendarResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return PutCalendarResponse.fromXContent(parser);
}
@Override
public PutCalendarAction.Response convertHlrcToInternal(PutCalendarResponse instance) {
org.elasticsearch.client.ml.calendars.Calendar hlrcCalendar = instance.getCalendar();
Calendar internalCalendar = new Calendar(hlrcCalendar.getId(), hlrcCalendar.getJobIds(), hlrcCalendar.getDescription());
return new PutCalendarAction.Response(internalCalendar);
}
@Override
protected PutCalendarAction.Response createBlankInstance() {
return new PutCalendarAction.Response();
}
}

View File

@ -10,7 +10,6 @@ import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.create.CreateIndexAction;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
import org.elasticsearch.action.search.SearchAction;
import org.elasticsearch.client.security.user.privileges.Role.ClusterPrivilegeName;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@ -66,7 +65,7 @@ public class LimitedRoleTests extends ESTestCase {
.putAlias(AliasMetaData.builder("_alias1"));
MetaData md = MetaData.builder().put(imbBuilder).put(imbBuilder1).build();
FieldPermissionsCache fieldPermissionsCache = new FieldPermissionsCache(Settings.EMPTY);
Role fromRole = Role.builder("a-role").cluster(Collections.singleton(ClusterPrivilegeName.MANAGE_SECURITY), Collections.emptyList())
Role fromRole = Role.builder("a-role").cluster(Collections.singleton("manage_security"), Collections.emptyList())
.add(IndexPrivilege.ALL, "_index").add(IndexPrivilege.CREATE_INDEX, "_index1").build();
IndicesAccessControl iac = fromRole.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(),
@ -84,7 +83,7 @@ public class LimitedRoleTests extends ESTestCase {
{
Role limitedByRole = Role.builder("limited-role")
.cluster(Collections.singleton(ClusterPrivilegeName.ALL), Collections.emptyList()).add(IndexPrivilege.READ, "_index")
.cluster(Collections.singleton("all"), Collections.emptyList()).add(IndexPrivilege.READ, "_index")
.add(IndexPrivilege.NONE, "_index1").build();
iac = limitedByRole.authorize(SearchAction.NAME, Sets.newHashSet("_index", "_alias1"), md.getAliasAndIndexLookup(),
fieldPermissionsCache);
@ -128,12 +127,12 @@ public class LimitedRoleTests extends ESTestCase {
}
public void testCheckClusterAction() {
Role fromRole = Role.builder("a-role").cluster(Collections.singleton(ClusterPrivilegeName.MANAGE_SECURITY), Collections.emptyList())
Role fromRole = Role.builder("a-role").cluster(Collections.singleton("manage_security"), Collections.emptyList())
.build();
assertThat(fromRole.checkClusterAction("cluster:admin/xpack/security/x", mock(TransportRequest.class)), is(true));
{
Role limitedByRole = Role.builder("limited-role")
.cluster(Collections.singleton(ClusterPrivilegeName.ALL), Collections.emptyList()).build();
.cluster(Collections.singleton("all"), Collections.emptyList()).build();
assertThat(limitedByRole.checkClusterAction("cluster:admin/xpack/security/x", mock(TransportRequest.class)), is(true));
assertThat(limitedByRole.checkClusterAction("cluster:other-action", mock(TransportRequest.class)), is(true));
Role role = LimitedRole.createLimitedRole(fromRole, limitedByRole);
@ -142,7 +141,7 @@ public class LimitedRoleTests extends ESTestCase {
}
{
Role limitedByRole = Role.builder("limited-role")
.cluster(Collections.singleton(ClusterPrivilegeName.MONITOR), Collections.emptyList()).build();
.cluster(Collections.singleton("monitor"), Collections.emptyList()).build();
assertThat(limitedByRole.checkClusterAction("cluster:monitor/me", mock(TransportRequest.class)), is(true));
Role role = LimitedRole.createLimitedRole(fromRole, limitedByRole);
assertThat(role.checkClusterAction("cluster:monitor/me", mock(TransportRequest.class)), is(false));
@ -199,14 +198,14 @@ public class LimitedRoleTests extends ESTestCase {
}
public void testCheckClusterPrivilege() {
Role fromRole = Role.builder("a-role").cluster(Collections.singleton(ClusterPrivilegeName.MANAGE_SECURITY), Collections.emptyList())
Role fromRole = Role.builder("a-role").cluster(Collections.singleton("manage_security"), Collections.emptyList())
.build();
assertThat(fromRole.grants(ClusterPrivilege.ALL), is(false));
assertThat(fromRole.grants(ClusterPrivilege.MANAGE_SECURITY), is(true));
{
Role limitedByRole = Role.builder("scoped-role")
.cluster(Collections.singleton(ClusterPrivilegeName.ALL), Collections.emptyList()).build();
.cluster(Collections.singleton("all"), Collections.emptyList()).build();
assertThat(limitedByRole.grants(ClusterPrivilege.ALL), is(true));
assertThat(limitedByRole.grants(ClusterPrivilege.MANAGE_SECURITY), is(true));
Role role = LimitedRole.createLimitedRole(fromRole, limitedByRole);
@ -215,7 +214,7 @@ public class LimitedRoleTests extends ESTestCase {
}
{
Role limitedByRole = Role.builder("scoped-role")
.cluster(Collections.singleton(ClusterPrivilegeName.MONITOR), Collections.emptyList()).build();
.cluster(Collections.singleton("monitor"), Collections.emptyList()).build();
assertThat(limitedByRole.grants(ClusterPrivilege.ALL), is(false));
assertThat(limitedByRole.grants(ClusterPrivilege.MONITOR), is(true));
Role role = LimitedRole.createLimitedRole(fromRole, limitedByRole);

View File

@ -12,7 +12,6 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
import org.elasticsearch.action.get.GetAction;
import org.elasticsearch.action.index.IndexAction;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.client.security.user.privileges.Role.ClusterPrivilegeName;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@ -1049,9 +1048,9 @@ public class CompositeRolesStoreTests extends ESTestCase {
doAnswer(invocationOnMock -> {
ActionListener<ApiKeyRoleDescriptors> listener = (ActionListener<ApiKeyRoleDescriptors>) invocationOnMock.getArguments()[1];
listener.onResponse(new ApiKeyRoleDescriptors("keyId",
Collections.singletonList(new RoleDescriptor("a-role", new String[] { ClusterPrivilegeName.ALL }, null, null)),
Collections.singletonList(new RoleDescriptor("a-role", new String[] {"all"}, null, null)),
Collections.singletonList(
new RoleDescriptor("scoped-role", new String[] { ClusterPrivilegeName.MANAGE_SECURITY }, null, null))));
new RoleDescriptor("scoped-role", new String[] {"manage_security"}, null, null))));
return Void.TYPE;
}).when(apiKeyService).getRoleForApiKey(eq(authentication), any(ActionListener.class));

View File

@ -14,6 +14,7 @@ dependencies {
testCompile project(path: xpackModule('core'), configuration: 'default')
testCompile project(path: xpackModule('security'), configuration: 'runtime')
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts') // to be moved in a later commit
testCompile ("org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}")
}
Closure waitWithAuth = { NodeInfo node, AntBuilder ant ->