Search in sources :

Example 21 with NamedWriteableRegistry

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);
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) ReleasableBytesReference(org.opensearch.common.bytes.ReleasableBytesReference) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TaskManager(org.opensearch.tasks.TaskManager) Before(org.junit.Before)

Example 22 with NamedWriteableRegistry

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;
                }
            }
        }
    }
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ClusterState(org.opensearch.cluster.ClusterState) RestClient(org.opensearch.client.RestClient) Client(org.opensearch.client.Client) RestCancellableNodeClient(org.opensearch.rest.action.RestCancellableNodeClient) RandomizingClient(org.opensearch.test.client.RandomizingClient) AdminClient(org.opensearch.client.AdminClient) ClusterAdminClient(org.opensearch.client.ClusterAdminClient)

Example 23 with NamedWriteableRegistry

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"));
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) IndexSettings(org.opensearch.index.IndexSettings) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 24 with NamedWriteableRegistry

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());
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) IndicesModule(org.opensearch.indices.IndicesModule) Before(org.junit.Before)

Example 25 with NamedWriteableRegistry

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));
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry)

Aggregations

NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)117 ThreadPool (org.opensearch.threadpool.ThreadPool)41 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)37 ClusterService (org.opensearch.cluster.service.ClusterService)37 TestThreadPool (org.opensearch.threadpool.TestThreadPool)37 AsynchronousSearchActiveStore (org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveStore)33 InternalAsynchronousSearchStats (org.opensearch.search.asynchronous.stats.InternalAsynchronousSearchStats)32 SubmitAsynchronousSearchRequest (org.opensearch.search.asynchronous.request.SubmitAsynchronousSearchRequest)30 TimeValue (org.opensearch.common.unit.TimeValue)29 SearchRequest (org.opensearch.action.search.SearchRequest)28 CountDownLatch (java.util.concurrent.CountDownLatch)26 User (org.opensearch.commons.authuser.User)24 AsynchronousSearchActiveContext (org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveContext)23 AsynchronousSearchTask (org.opensearch.search.asynchronous.task.AsynchronousSearchTask)22 NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)21 SearchModule (org.opensearch.search.SearchModule)20 StreamInput (org.opensearch.common.io.stream.StreamInput)19 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)18 ArrayList (java.util.ArrayList)16 Version (org.opensearch.Version)16