Search in sources :

Example 21 with OutputStreamStreamOutput

use of org.elasticsearch.common.io.stream.OutputStreamStreamOutput in project crate by crate.

the class StoreTests method testMetadataSnapshotStreaming.

public void testMetadataSnapshotStreaming() throws Exception {
    Store.MetadataSnapshot outMetadataSnapshot = createMetadataSnapshot();
    org.elasticsearch.Version targetNodeVersion = randomVersion(random());
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
    out.setVersion(targetNodeVersion);
    outMetadataSnapshot.writeTo(out);
    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    in.setVersion(targetNodeVersion);
    Store.MetadataSnapshot inMetadataSnapshot = new Store.MetadataSnapshot(in);
    Map<String, StoreFileMetadata> origEntries = new HashMap<>();
    origEntries.putAll(outMetadataSnapshot.asMap());
    for (Map.Entry<String, StoreFileMetadata> entry : inMetadataSnapshot.asMap().entrySet()) {
        assertThat(entry.getValue().name(), equalTo(origEntries.remove(entry.getKey()).name()));
    }
    assertThat(origEntries.size(), equalTo(0));
    assertThat(inMetadataSnapshot.getCommitUserData(), equalTo(outMetadataSnapshot.getCommitUserData()));
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) HashMap(java.util.HashMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput)

Example 22 with OutputStreamStreamOutput

use of org.elasticsearch.common.io.stream.OutputStreamStreamOutput in project crate by crate.

the class StoreTests method testStreamStoreFilesMetadata.

public void testStreamStoreFilesMetadata() throws Exception {
    Store.MetadataSnapshot metadataSnapshot = createMetadataSnapshot();
    int numOfLeases = randomIntBetween(0, 10);
    List<RetentionLease> peerRecoveryRetentionLeases = new ArrayList<>();
    for (int i = 0; i < numOfLeases; i++) {
        peerRecoveryRetentionLeases.add(new RetentionLease(ReplicationTracker.getPeerRecoveryRetentionLeaseId(UUIDs.randomBase64UUID()), randomNonNegativeLong(), randomNonNegativeLong(), ReplicationTracker.PEER_RECOVERY_RETENTION_LEASE_SOURCE));
    }
    TransportNodesListShardStoreMetadata.StoreFilesMetadata outStoreFileMetadata = new TransportNodesListShardStoreMetadata.StoreFilesMetadata(new ShardId("test", "_na_", 0), metadataSnapshot, peerRecoveryRetentionLeases);
    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
    org.elasticsearch.Version targetNodeVersion = randomVersion(random());
    out.setVersion(targetNodeVersion);
    outStoreFileMetadata.writeTo(out);
    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    in.setVersion(targetNodeVersion);
    TransportNodesListShardStoreMetadata.StoreFilesMetadata inStoreFileMetadata = new TransportNodesListShardStoreMetadata.StoreFilesMetadata(in);
    Iterator<StoreFileMetadata> outFiles = outStoreFileMetadata.iterator();
    for (StoreFileMetadata inFile : inStoreFileMetadata) {
        assertThat(inFile.name(), equalTo(outFiles.next().name()));
    }
    assertThat(outStoreFileMetadata.syncId(), equalTo(inStoreFileMetadata.syncId()));
    assertThat(outStoreFileMetadata.peerRecoveryRetentionLeases(), equalTo(peerRecoveryRetentionLeases));
}
Also used : ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ShardId(org.elasticsearch.index.shard.ShardId) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) RetentionLease(org.elasticsearch.index.seqno.RetentionLease) ByteArrayInputStream(java.io.ByteArrayInputStream) TransportNodesListShardStoreMetadata(org.elasticsearch.indices.store.TransportNodesListShardStoreMetadata) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput)

Aggregations

OutputStreamStreamOutput (org.elasticsearch.common.io.stream.OutputStreamStreamOutput)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 ByteArrayInputStream (java.io.ByteArrayInputStream)16 InputStreamStreamInput (org.elasticsearch.common.io.stream.InputStreamStreamInput)16 StreamOutput (org.elasticsearch.common.io.stream.StreamOutput)9 Test (org.junit.Test)6 CrateUnitTest (io.crate.test.integration.CrateUnitTest)5 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)3 ShardId (org.elasticsearch.index.shard.ShardId)3 ThreadPools (io.crate.monitor.ThreadPools)2 BufferedOutputStream (java.io.BufferedOutputStream)2 OutputStream (java.io.OutputStream)2 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Deflater (java.util.zip.Deflater)2 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)2 Version (org.elasticsearch.Version)2 BytesReference (org.elasticsearch.common.bytes.BytesReference)2