use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.
the class InboundHandlerTests method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
taskManager = new TaskManager(Settings.EMPTY, threadPool, Collections.emptySet());
channel = new FakeTcpChannel(randomBoolean(), buildNewFakeTransportAddress().address(), buildNewFakeTransportAddress().address()) {
public void sendMessage(BytesReference reference, org.opensearch.action.ActionListener<Void> listener) {
super.sendMessage(reference, listener);
if (listener != null) {
listener.onResponse(null);
}
}
};
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
TransportHandshaker handshaker = new TransportHandshaker(version, threadPool, (n, c, r, v) -> {
});
outboundHandler = new OutboundHandler("node", version, new String[0], new StatsTracker(), threadPool, BigArrays.NON_RECYCLING_INSTANCE);
TransportKeepAlive keepAlive = new TransportKeepAlive(threadPool, outboundHandler::sendBytes);
requestHandlers = new Transport.RequestHandlers();
responseHandlers = new Transport.ResponseHandlers();
handler = new InboundHandler(threadPool, outboundHandler, namedWriteableRegistry, handshaker, keepAlive, requestHandlers, responseHandlers);
}
use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.
the class OpenSearchIntegTestCase method ensureClusterStateConsistency.
/**
* Verifies that all nodes that have the same version of the cluster state as master have same cluster state
*/
protected void ensureClusterStateConsistency() throws IOException {
if (cluster() != null && cluster().size() > 0) {
final NamedWriteableRegistry namedWriteableRegistry = cluster().getNamedWriteableRegistry();
final Client masterClient = client();
ClusterState masterClusterState = masterClient.admin().cluster().prepareState().all().get().getState();
byte[] masterClusterStateBytes = ClusterState.Builder.toBytes(masterClusterState);
// remove local node reference
masterClusterState = ClusterState.Builder.fromBytes(masterClusterStateBytes, null, namedWriteableRegistry);
Map<String, Object> masterStateMap = convertToMap(masterClusterState);
int masterClusterStateSize = masterClusterState.toString().length();
String masterId = masterClusterState.nodes().getMasterNodeId();
for (Client client : cluster().getClients()) {
ClusterState localClusterState = client.admin().cluster().prepareState().all().setLocal(true).get().getState();
byte[] localClusterStateBytes = ClusterState.Builder.toBytes(localClusterState);
// remove local node reference
localClusterState = ClusterState.Builder.fromBytes(localClusterStateBytes, null, namedWriteableRegistry);
final Map<String, Object> localStateMap = convertToMap(localClusterState);
final int localClusterStateSize = localClusterState.toString().length();
// that the master node matches the master (otherwise there is no requirement for the cluster state to match)
if (masterClusterState.version() == localClusterState.version() && masterId.equals(localClusterState.nodes().getMasterNodeId())) {
try {
assertEquals("cluster state UUID does not match", masterClusterState.stateUUID(), localClusterState.stateUUID());
// We cannot compare serialization bytes since serialization order of maps is not guaranteed
// We also cannot compare byte array size because CompressedXContent's DeflateCompressor uses
// a synced flush that can affect the size of the compressed byte array
// (see: DeflateCompressedXContentTests#testDifferentCompressedRepresentation for an example)
// instead we compare the string length of cluster state - they should be the same
assertEquals("cluster state size does not match", masterClusterStateSize, localClusterStateSize);
// Compare JSON serialization
assertNull("cluster state JSON serialization does not match", differenceBetweenMapsIgnoringArrayOrder(masterStateMap, localStateMap));
} catch (final AssertionError error) {
logger.error("Cluster state from master:\n{}\nLocal cluster state:\n{}", masterClusterState.toString(), localClusterState.toString());
throw error;
}
}
}
}
}
use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.
the class QueryShardContextTests method testIndexSortedOnField.
public void testIndexSortedOnField() {
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).put("index.sort.field", "sort_field").build();
IndexMetadata indexMetadata = new IndexMetadata.Builder("index").settings(settings).build();
IndexSettings indexSettings = new IndexSettings(indexMetadata, settings);
QueryShardContext context = new QueryShardContext(0, indexSettings, BigArrays.NON_RECYCLING_INSTANCE, null, null, null, null, null, NamedXContentRegistry.EMPTY, new NamedWriteableRegistry(Collections.emptyList()), null, null, () -> 0L, null, null, () -> true, null);
assertTrue(context.indexSortedOnField("sort_field"));
assertFalse(context.indexSortedOnField("second_sort_field"));
assertFalse(context.indexSortedOnField("non_sort_field"));
}
use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.
the class RolloverRequestTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
writeableRegistry = new NamedWriteableRegistry(new IndicesModule(Collections.emptyList()).getNamedWriteables());
}
use of org.opensearch.common.io.stream.NamedWriteableRegistry in project OpenSearch by opensearch-project.
the class ShardsAcknowledgedResponseTests method testSerialization.
public void testSerialization() throws Exception {
ShardsAcknowledgedResponse testInstance = new TestImpl(true, true);
ShardsAcknowledgedResponse result = copyWriteable(testInstance, new NamedWriteableRegistry(Collections.emptyList()), in -> new TestImpl(in, true), Version.CURRENT);
assertThat(result.isAcknowledged(), is(true));
assertThat(result.isShardsAcknowledged(), is(true));
}
Aggregations