use of com.orientechnologies.orient.core.storage.ORawBuffer in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testAllocatePositionMap.
public void testAllocatePositionMap() throws IOException {
OPhysicalPosition position = paginatedCluster.allocatePosition((byte) 'd');
Assert.assertTrue(position.clusterPosition >= 0);
ORawBuffer rec = paginatedCluster.readRecord(position.clusterPosition, false);
Assert.assertNull(rec);
paginatedCluster.createRecord(new byte[20], 1, (byte) 'd', position);
rec = paginatedCluster.readRecord(position.clusterPosition, false);
Assert.assertNotNull(rec);
}
use of com.orientechnologies.orient.core.storage.ORawBuffer in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testRemoveHalfBigRecords.
public void testRemoveHalfBigRecords() throws IOException {
final int records = 5000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testRemoveHalfBigRecords seed : " + seed);
Map<Long, byte[]> positionRecordMap = new HashMap<Long, byte[]>();
int recordVersion = 0;
recordVersion++;
recordVersion++;
for (int i = 0; i < records; i++) {
int recordSize = mersenneTwisterFast.nextInt(2 * OClusterPage.MAX_RECORD_SIZE) + OClusterPage.MAX_RECORD_SIZE + 1;
byte[] bigRecord = new byte[recordSize];
mersenneTwisterFast.nextBytes(bigRecord);
final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(bigRecord, recordVersion, (byte) 2, null);
positionRecordMap.put(physicalPosition.clusterPosition, bigRecord);
}
int deletedRecords = 0;
Assert.assertEquals(records, paginatedCluster.getEntries());
Set<Long> deletedPositions = new HashSet<Long>();
Iterator<Long> positionIterator = positionRecordMap.keySet().iterator();
while (positionIterator.hasNext()) {
long clusterPosition = positionIterator.next();
if (mersenneTwisterFast.nextBoolean()) {
deletedPositions.add(clusterPosition);
Assert.assertTrue(paginatedCluster.deleteRecord(clusterPosition));
deletedRecords++;
Assert.assertEquals(records - deletedRecords, paginatedCluster.getEntries());
positionIterator.remove();
}
}
Assert.assertEquals(paginatedCluster.getEntries(), records - deletedRecords);
for (long deletedPosition : deletedPositions) {
Assert.assertNull(paginatedCluster.readRecord(deletedPosition, false));
Assert.assertFalse(paginatedCluster.deleteRecord(deletedPosition));
}
for (Map.Entry<Long, byte[]> entry : positionRecordMap.entrySet()) {
ORawBuffer rawBuffer = paginatedCluster.readRecord(entry.getKey(), false);
Assert.assertNotNull(rawBuffer);
Assert.assertEquals(rawBuffer.version, recordVersion);
Assert.assertEquals(rawBuffer.buffer, entry.getValue());
Assert.assertEquals(rawBuffer.recordType, 2);
}
}
use of com.orientechnologies.orient.core.storage.ORawBuffer in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testUpdateOneBigRecord.
public void testUpdateOneBigRecord() throws IOException {
byte[] bigRecord = new byte[2 * 65536 + 100];
Random mersenneTwisterFast = new Random();
mersenneTwisterFast.nextBytes(bigRecord);
int recordVersion = 0;
recordVersion++;
recordVersion++;
OPhysicalPosition physicalPosition = paginatedCluster.createRecord(bigRecord, recordVersion, (byte) 1, null);
Assert.assertEquals(physicalPosition.clusterPosition, 0);
recordVersion++;
bigRecord = new byte[2 * 65536 + 20];
mersenneTwisterFast.nextBytes(bigRecord);
paginatedCluster.updateRecord(physicalPosition.clusterPosition, bigRecord, recordVersion, (byte) 2);
ORawBuffer rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
Assert.assertNotNull(rawBuffer);
Assert.assertEquals(rawBuffer.version, recordVersion);
Assert.assertEquals(rawBuffer.buffer, bigRecord);
Assert.assertEquals(rawBuffer.recordType, 2);
}
use of com.orientechnologies.orient.core.storage.ORawBuffer in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testUpdateOneSmallRecordVersionIsLowerCurrentOne.
public void testUpdateOneSmallRecordVersionIsLowerCurrentOne() throws IOException {
byte[] smallRecord = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int recordVersion = 0;
recordVersion++;
recordVersion++;
OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 1, null);
Assert.assertEquals(physicalPosition.clusterPosition, 0);
int updateRecordVersion = 0;
updateRecordVersion++;
smallRecord = new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3 };
paginatedCluster.updateRecord(physicalPosition.clusterPosition, smallRecord, updateRecordVersion, (byte) 2);
ORawBuffer rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
Assert.assertNotNull(rawBuffer);
Assert.assertEquals(rawBuffer.version, updateRecordVersion);
Assert.assertEquals(rawBuffer.buffer, smallRecord);
Assert.assertEquals(rawBuffer.recordType, 2);
}
use of com.orientechnologies.orient.core.storage.ORawBuffer in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testManyAllocatePositionMap.
public void testManyAllocatePositionMap() throws IOException {
final int records = 10000;
List<OPhysicalPosition> positions = new ArrayList<OPhysicalPosition>();
for (int i = 0; i < records; i++) {
OPhysicalPosition position = paginatedCluster.allocatePosition((byte) 'd');
Assert.assertTrue(position.clusterPosition >= 0);
ORawBuffer rec = paginatedCluster.readRecord(position.clusterPosition, false);
Assert.assertNull(rec);
positions.add(position);
}
for (int i = 0; i < records; i++) {
OPhysicalPosition position = positions.get(i);
paginatedCluster.createRecord(new byte[20], 1, (byte) 'd', position);
ORawBuffer rec = paginatedCluster.readRecord(position.clusterPosition, false);
Assert.assertNotNull(rec);
}
}
Aggregations