added -> net.openhft.chronicle.map.ValueAlignmentRelocation.testValueAlignmentRelocation

This commit is contained in:
Rob Austin
2018-12-05 10:55:59 +00:00
parent f1ed4cad99
commit 3347b6ce07
@@ -0,0 +1,50 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.Random;
public class ValueAlignmentRelocation {
@Test
public void testValueAlignmentRelocation() {
ChronicleMap<byte[], byte[]> map = ChronicleMapBuilder
.of(byte[].class, byte[].class)
.averageKeySize(5)
.averageValueSize(5)
.keySizeMarshaller(SizeMarshaller.stopBit())
.valueSizeMarshaller(SizeMarshaller.stopBit())
.entryAndValueOffsetAlignment(8)
.actualSegments(1)
.actualChunkSize(2)
.entries(10)
.create();
Random r = new Random(0);
for (int firstKeySize = 1; firstKeySize < 10; firstKeySize++) {
byte[] firstKey = new byte[firstKeySize];
byte[] firstValue = new byte[8];
r.nextBytes(firstKey);
r.nextBytes(firstValue);
for (int secondKeySize = 1; secondKeySize < 10; secondKeySize++) {
byte[] secondKey = new byte[secondKeySize];
r.nextBytes(secondKey);
byte[] secondValue = new byte[1];
r.nextBytes(secondValue);
map.clear();
map.put(firstKey, firstValue);
map.put(secondKey, secondValue);
byte[] thirdValue = new byte[16];
r.nextBytes(thirdValue);
map.put(firstKey, thirdValue);
for (int i = 0; i < 10; i++) {
map.put(new byte[]{(byte) i}, new byte[]{(byte) i});
}
Assert.assertTrue(Arrays.equals(map.get(firstKey), thirdValue));
}
}
}
}