forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add realistic hlrc request serialization test base class and
change hlrc ccr request tests to use AbstractRequestTestCase base class. This way the request classes are tested in a more realistic setting. Note this change also adds a test dependency on xpack core module. Similar to elastic#39844 but then for hlrc request serialization tests. Relates to elastic#39745
- Loading branch information
Showing
5 changed files
with
145 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractRequestTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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; | ||
|
||
import org.elasticsearch.cluster.ClusterModule; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
import org.elasticsearch.common.xcontent.XContent; | ||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Base class for HLRC request parsing tests. | ||
* | ||
* This case class facilitates generating client side request test instances and | ||
* verifies that they are correctly parsed into server side request instances. | ||
* | ||
* @param <C> The class representing the request on the client side. | ||
* @param <S> The class representing the request on the server side. | ||
*/ | ||
public abstract class AbstractRequestTestCase<C extends ToXContent, S> extends ESTestCase { | ||
|
||
private static final int NUMBER_OF_TEST_RUNS = 20; | ||
|
||
public final void testFromXContent() throws IOException { | ||
for (int i = 0; i < NUMBER_OF_TEST_RUNS; i++) { | ||
final C clientTestInstance = createClientTestInstance(); | ||
|
||
final XContentType xContentType = randomFrom(XContentType.values()); | ||
final BytesReference bytes = toShuffledXContent(clientTestInstance, xContentType, ToXContent.EMPTY_PARAMS, randomBoolean()); | ||
|
||
final XContent xContent = XContentFactory.xContent(xContentType); | ||
final XContentParser parser = xContent.createParser( | ||
new NamedXContentRegistry(ClusterModule.getNamedXWriteables()), | ||
LoggingDeprecationHandler.INSTANCE, | ||
bytes.streamInput()); | ||
final S serverInstance = doParseToServerInstance(parser); | ||
assertInstances(serverInstance, clientTestInstance); | ||
} | ||
} | ||
|
||
protected abstract C createClientTestInstance(); | ||
|
||
protected abstract S doParseToServerInstance(XContentParser parser) throws IOException; | ||
|
||
protected abstract void assertInstances(S serverInstance, C clientTestInstance); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters