Search in sources :

Example 11 with KeyInputStream

use of org.apache.hadoop.ozone.client.io.KeyInputStream in project ozone by apache.

the class TestChunkStreams method testReadGroupInputStream.

@Test
public void testReadGroupInputStream() throws Exception {
    try (KeyInputStream groupInputStream = new KeyInputStream()) {
        String dataString = RandomStringUtils.randomAscii(500);
        byte[] buf = dataString.getBytes(UTF_8);
        int offset = 0;
        for (int i = 0; i < 5; i++) {
            int tempOffset = offset;
            BlockInputStream in = new BlockInputStream(null, 100, null, null, true, null) {

                private long pos = 0;

                private ByteArrayInputStream in = new ByteArrayInputStream(buf, tempOffset, 100);

                @Override
                public synchronized void seek(long pos) throws IOException {
                    throw new UnsupportedOperationException();
                }

                @Override
                public synchronized long getPos() {
                    return pos;
                }

                @Override
                public boolean seekToNewSource(long targetPos) throws IOException {
                    throw new UnsupportedOperationException();
                }

                @Override
                public synchronized int read() throws IOException {
                    return in.read();
                }

                @Override
                public synchronized int read(byte[] b, int off, int len) throws IOException {
                    int readLen = in.read(b, off, len);
                    pos += readLen;
                    return readLen;
                }
            };
            offset += 100;
            groupInputStream.addStream(in);
        }
        byte[] resBuf = new byte[500];
        int len = groupInputStream.read(resBuf, 0, 500);
        assertEquals(500, len);
        assertEquals(dataString, new String(resBuf, UTF_8));
    }
}
Also used : BlockInputStream(org.apache.hadoop.hdds.scm.storage.BlockInputStream) KeyInputStream(org.apache.hadoop.ozone.client.io.KeyInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

KeyInputStream (org.apache.hadoop.ozone.client.io.KeyInputStream)11 BlockInputStream (org.apache.hadoop.hdds.scm.storage.BlockInputStream)5 ChunkInputStream (org.apache.hadoop.hdds.scm.storage.ChunkInputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 XceiverClientMetrics (org.apache.hadoop.hdds.scm.XceiverClientMetrics)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)1 OmKeyArgs (org.apache.hadoop.ozone.om.helpers.OmKeyArgs)1 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)1 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)1 OmKeyLocationInfoGroup (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup)1