forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71a9f8d
commit 84cd141
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
server/src/test/java/org/elasticsearch/index/translog/BufferedChecksumStreamInputTests.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,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.index.translog; | ||
|
||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.io.stream.AbstractStreamTests; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
|
||
import java.io.IOException; | ||
import java.util.zip.CRC32; | ||
|
||
public class BufferedChecksumStreamInputTests extends AbstractStreamTests { | ||
|
||
@Override | ||
protected StreamInput getStreamInput(BytesReference bytesReference) { | ||
return new BufferedChecksumStreamInput(StreamInput.wrap(BytesReference.toBytes(bytesReference)), "test"); | ||
} | ||
|
||
public void testChecksum() throws IOException { | ||
int bytesSize = randomIntBetween(512, 2048); | ||
byte[] bytes = randomByteArrayOfLength(bytesSize); | ||
CRC32 crc32 = new CRC32(); | ||
crc32.update(bytes); | ||
|
||
try (BufferedChecksumStreamInput input = new BufferedChecksumStreamInput(StreamInput.wrap(bytes), "test")) { | ||
int read = input.read(new byte[bytesSize]); | ||
assertEquals(bytesSize, read); | ||
assertEquals(-1, input.read()); | ||
assertEquals(crc32.getValue(), input.getChecksum()); | ||
} | ||
} | ||
} |