use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class ClusterDebugInfoTest method testTwoPagesRecordDebugInfo.
@Test
public void testTwoPagesRecordDebugInfo() throws IOException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:ClusterDebugInfoTest");
db.create();
try {
OStorage storage = db.getStorage();
int defaultId = storage.getDefaultClusterId();
OPaginatedCluster cluster = (OPaginatedCluster) storage.getClusterById(defaultId);
int size = OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger();
int half = size / 2;
byte[] content = new byte[(size + half) * 1024];
OStorageOperationResult<OPhysicalPosition> result = storage.createRecord(new ORecordId(defaultId), content, 0, (byte) 'b', OPERATION_MODE.SYNCHRONOUS.ordinal(), null);
OPaginatedClusterDebug debug = cluster.readDebug(result.getResult().clusterPosition);
Assert.assertEquals(debug.pages.size(), 2);
Assert.assertEquals(debug.clusterPosition, result.getResult().clusterPosition);
Assert.assertNotEquals(debug.contentSize, 0);
Assert.assertFalse(debug.empty);
Assert.assertNotEquals(debug.pages.get(0).pageIndex, -1);
Assert.assertNotEquals(debug.pages.get(0).inPagePosition, -1);
Assert.assertNotEquals(debug.pages.get(0).inPageSize, -1);
Assert.assertNotNull(debug.pages.get(0).content);
Assert.assertNotEquals(debug.pages.get(1).pageIndex, -1);
Assert.assertNotEquals(debug.pages.get(1).inPagePosition, -1);
Assert.assertNotEquals(debug.pages.get(1).inPageSize, -1);
Assert.assertNotNull(debug.pages.get(1).content);
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testRemoveHalfSmallRecords.
public void testRemoveHalfSmallRecords() throws IOException {
final int records = 10000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testRemoveHalfSmallRecords 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(OClusterPage.MAX_RECORD_SIZE - 1) + 1;
byte[] smallRecord = new byte[recordSize];
mersenneTwisterFast.nextBytes(smallRecord);
final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 2, null);
positionRecordMap.put(physicalPosition.clusterPosition, smallRecord);
}
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.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testAddManyRecords.
public void testAddManyRecords() throws IOException {
final int records = 10000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testAddManyRecords 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) + 1;
byte[] smallRecord = new byte[recordSize];
mersenneTwisterFast.nextBytes(smallRecord);
final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 2, null);
positionRecordMap.put(physicalPosition.clusterPosition, smallRecord);
}
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.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testAddOneSmallRecord.
public void testAddOneSmallRecord() 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);
ORawBuffer rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
Assert.assertNotNull(rawBuffer);
Assert.assertEquals(rawBuffer.version, recordVersion);
Assert.assertEquals(rawBuffer.buffer, smallRecord);
Assert.assertEquals(rawBuffer.recordType, 1);
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testAddManyBigRecords.
public void testAddManyBigRecords() throws IOException {
final int records = 5000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testAddManyBigRecords 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);
}
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);
}
}
Aggregations