Skip to content

Commit

Permalink
Fix a bug in volt table compression methods, and add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
aweisberg committed Jul 3, 2012
1 parent 583a52a commit b13e366
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/frontend/org/voltdb/VoltTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,10 @@ public byte[] getCompressedBytes() throws IOException {
return CompressionService.compressBuffer(m_buffer);
} else {
assert(m_buffer.hasArray());
return CompressionService.compressBytes(m_buffer.array(), m_buffer.position(), m_buffer.limit());
return CompressionService.compressBytes(
m_buffer.array(),
m_buffer.arrayOffset() + m_buffer.position(),
m_buffer.limit());
}
} finally {
m_buffer.position(startPosition);
Expand All @@ -1325,7 +1328,10 @@ public Future<byte[]> getCompressedBytesAsync() throws IOException {
return CompressionService.compressBufferAsync(m_buffer.duplicate());
} else {
assert(m_buffer.hasArray());
return CompressionService.compressBytesAsync(m_buffer.array(), m_buffer.position(), m_buffer.limit());
return CompressionService.compressBytesAsync(
m_buffer.array(),
m_buffer.arrayOffset() + m_buffer.position(),
m_buffer.limit());
}
} finally {
m_buffer.position(startPosition);
Expand Down
52 changes: 52 additions & 0 deletions tests/frontend/org/voltdb/TestVoltTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,58 @@ public void testResizedTable() {
}
}

/*
* Use a heap buffer with an array offset to simulate a result set
* from the EE
*/
public void testCompressionWithArrayOffset() throws Exception {
testResizedTable();
ByteBuffer buf = t.getBuffer();
byte bytes[] = new byte[buf.remaining() + 12];
byte subBytes[] = new byte[buf.remaining()];
buf.get(subBytes);
System.arraycopy(subBytes, 0, bytes, 12, subBytes.length);

buf = ByteBuffer.wrap(bytes);
buf.position(12);
buf = buf.slice();

VoltTable vt = PrivateVoltTableFactory.createVoltTableFromBuffer(buf, true);

FastSerializer fs = new FastSerializer();
fs.writeObject(t);

byte uncompressedBytes[] = fs.getBytes();


/*
* Test the sync method
*/
byte decompressedBytes[] = CompressionService
.decompressBytes(vt.getCompressedBytes());
vt = PrivateVoltTableFactory.createVoltTableFromBuffer(
ByteBuffer.wrap(decompressedBytes), true);
fs = new FastSerializer();
fs.writeObject(vt);
byte bytesForComparison[] = fs.getBytes();
assertTrue(java.util.Arrays.equals(bytesForComparison,
uncompressedBytes));

/*
* Now test async
*/
vt = PrivateVoltTableFactory.createVoltTableFromBuffer(buf, true);
decompressedBytes = CompressionService
.decompressBytes(vt.getCompressedBytes());
vt = PrivateVoltTableFactory.createVoltTableFromBuffer(
ByteBuffer.wrap(decompressedBytes), true);
fs = new FastSerializer();
fs.writeObject(vt);
bytesForComparison = fs.getBytes();
assertTrue(java.util.Arrays.equals(bytesForComparison,
uncompressedBytes));
}

public void testCompression() throws Exception {
testResizedTable();
byte compressedBytes[] = t.getCompressedBytes();
Expand Down

0 comments on commit b13e366

Please sign in to comment.