use of com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebug in project orientdb by orientechnologies.
the class ORecordSerializerBinaryDebugTest method testSimpleBrokenDocumentDebug.
@Test
public void testSimpleBrokenDocumentDebug() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + ORecordSerializerBinaryDebugTest.class.getSimpleName());
db.create();
try {
ODocument doc = new ODocument();
doc.field("test", "test");
doc.field("anInt", 2);
doc.field("anDouble", 2D);
byte[] bytes = doc.toStream();
byte[] brokenBytes = new byte[bytes.length - 10];
System.arraycopy(bytes, 0, brokenBytes, 0, bytes.length - 10);
ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug();
ORecordSerializationDebug debug = debugger.deserializeDebug(brokenBytes, db);
assertEquals(debug.properties.size(), 3);
assertEquals(debug.properties.get(0).name, "test");
assertEquals(debug.properties.get(0).type, OType.STRING);
assertEquals(debug.properties.get(0).faildToRead, true);
assertNotNull(debug.properties.get(0).readingException);
assertEquals(debug.properties.get(1).name, "anInt");
assertEquals(debug.properties.get(1).type, OType.INTEGER);
assertEquals(debug.properties.get(1).faildToRead, true);
assertNotNull(debug.properties.get(1).readingException);
assertEquals(debug.properties.get(2).name, "anDouble");
assertEquals(debug.properties.get(2).type, OType.DOUBLE);
assertEquals(debug.properties.get(2).faildToRead, true);
assertNotNull(debug.properties.get(2).readingException);
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebug in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method displayRawRecord.
@ConsoleCommand(description = "Display a record as raw bytes", onlineHelp = "Console-Command-Display-Raw-Record")
public void displayRawRecord(@ConsoleParameter(name = "rid", description = "The record id to display") final String iRecordId) throws IOException {
checkForDatabase();
ORecordId rid;
if (iRecordId.indexOf(':') > -1)
rid = new ORecordId(iRecordId);
else {
OIdentifiable rec = setCurrentRecord(Integer.parseInt(iRecordId));
if (rec != null)
rid = (ORecordId) rec.getIdentity();
else
return;
}
ORawBuffer record;
ORecordId id = new ORecordId(rid);
if (!(currentDatabase.getStorage() instanceof OLocalPaginatedStorage)) {
record = currentDatabase.getStorage().readRecord(rid, null, false, false, null).getResult();
if (record != null) {
String content;
if (Integer.parseInt(properties.get("maxBinaryDisplay")) < record.buffer.length)
content = new String(Arrays.copyOf(record.buffer, Integer.parseInt(properties.get("maxBinaryDisplay"))));
else
content = new String(record.buffer);
out.println("\nRaw record content. The size is " + record.buffer.length + " bytes, while settings force to print first " + content.length() + " bytes:\n\n" + content);
}
} else {
final OLocalPaginatedStorage storage = (OLocalPaginatedStorage) currentDatabase.getStorage();
final OPaginatedCluster cluster = (OPaginatedCluster) storage.getClusterById(id.getClusterId());
if (cluster == null) {
message("\n cluster with id %i does not exist", id.getClusterId());
return;
}
message("\n\nLOW LEVEL CLUSTER INFO");
final OPaginatedCluster.RECORD_STATUS status = cluster.getRecordStatus(id.getClusterPosition());
message("\n status: %s", status);
final OPaginatedClusterDebug debugInfo = cluster.readDebug(id.getClusterPosition());
message("\n cluster fieldId: %d", debugInfo.fileId);
message("\n cluster name: %s", cluster.getName());
message("\n in cluster position: %d", debugInfo.clusterPosition);
message("\n empty: %b", debugInfo.empty);
message("\n contentSize: %d", debugInfo.contentSize);
message("\n n-pages: %d", debugInfo.pages.size());
message("\n\n +----------PAGE_ID---------------+------IN_PAGE_POSITION----------+---------IN_PAGE_SIZE-----------+----PAGE_CONTENT---->> ");
for (OClusterPageDebug page : debugInfo.pages) {
message("\n |%30d ", page.pageIndex);
message(" |%30d ", page.inPagePosition);
message(" |%30d ", page.inPageSize);
message(" |%s", OBase64Utils.encodeBytes(page.content));
}
record = cluster.readRecord(id.getClusterPosition(), false);
}
if (record == null)
throw new OSystemException("The record has been deleted");
if ("ORecordSerializerBinary".equals(currentDatabase.getSerializer().toString())) {
byte[] buff = record.getBuffer();
ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug();
ORecordSerializationDebug deserializeDebug = debugger.deserializeDebug(buff, currentDatabase);
message("\n\nRECORD CONTENT INFO");
message("\n class name: %s", deserializeDebug.className);
message("\n fail on Reading: %b", deserializeDebug.readingFailure);
message("\n fail position: %d", deserializeDebug.failPosition);
if (deserializeDebug.readingException != null) {
StringWriter writer = new StringWriter();
deserializeDebug.readingException.printStackTrace(new PrintWriter(writer));
message("\n Exception On Reading: %s", writer.getBuffer().toString());
}
message("\n number of properties : %d", deserializeDebug.properties.size());
message("\n\n PROPERTIES");
for (ORecordSerializationDebugProperty prop : deserializeDebug.properties) {
message("\n property name: %s", prop.name);
message("\n property type: %s", prop.type.name());
message("\n property globalId: %d", prop.globalId);
message("\n fail on reading: %b", prop.faildToRead);
if (prop.faildToRead) {
message("\n failed on reading position: %b", prop.failPosition);
StringWriter writer = new StringWriter();
prop.readingException.printStackTrace(new PrintWriter(writer));
message("\n Exception on reading: %s", writer.getBuffer().toString());
} else {
if (prop.value instanceof ORidBag) {
message("\n property value: ORidBug ");
((ORidBag) prop.value).debugPrint(System.out);
} else
message("\n property value: %s", prop.value != null ? prop.value.toString() : "null");
}
message("\n");
}
}
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebug in project orientdb by orientechnologies.
the class ORecordSerializerBinaryDebugTest method testSchemaFullDocumentDebug.
@Test
public void testSchemaFullDocumentDebug() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + ORecordSerializerBinaryDebugTest.class.getSimpleName());
db.create();
try {
OClass clazz = db.getMetadata().getSchema().createClass("some");
clazz.createProperty("testP", OType.STRING);
clazz.createProperty("theInt", OType.INTEGER);
ODocument doc = new ODocument("some");
doc.field("testP", "test");
doc.field("theInt", 2);
doc.field("anDouble", 2D);
byte[] bytes = doc.toStream();
ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug();
ORecordSerializationDebug debug = debugger.deserializeDebug(bytes, db);
assertEquals(debug.properties.size(), 3);
assertEquals(debug.properties.get(0).name, "testP");
assertEquals(debug.properties.get(0).type, OType.STRING);
assertEquals(debug.properties.get(0).value, "test");
assertEquals(debug.properties.get(1).name, "theInt");
assertEquals(debug.properties.get(1).type, OType.INTEGER);
assertEquals(debug.properties.get(1).value, 2);
assertEquals(debug.properties.get(2).name, "anDouble");
assertEquals(debug.properties.get(2).type, OType.DOUBLE);
assertEquals(debug.properties.get(2).value, 2D);
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebug in project orientdb by orientechnologies.
the class ORecordSerializerBinaryDebugTest method testBrokenSchemaFullDocumentDebug.
@Test
public void testBrokenSchemaFullDocumentDebug() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + ORecordSerializerBinaryDebugTest.class.getSimpleName());
db.create();
try {
OClass clazz = db.getMetadata().getSchema().createClass("some");
clazz.createProperty("testP", OType.STRING);
clazz.createProperty("theInt", OType.INTEGER);
ODocument doc = new ODocument("some");
doc.field("testP", "test");
doc.field("theInt", 2);
doc.field("anDouble", 2D);
byte[] bytes = doc.toStream();
byte[] brokenBytes = new byte[bytes.length - 10];
System.arraycopy(bytes, 0, brokenBytes, 0, bytes.length - 10);
ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug();
ORecordSerializationDebug debug = debugger.deserializeDebug(brokenBytes, db);
assertEquals(debug.properties.size(), 3);
assertEquals(debug.properties.get(0).name, "testP");
assertEquals(debug.properties.get(0).type, OType.STRING);
assertEquals(debug.properties.get(0).faildToRead, true);
assertNotNull(debug.properties.get(0).readingException);
assertEquals(debug.properties.get(1).name, "theInt");
assertEquals(debug.properties.get(1).type, OType.INTEGER);
assertEquals(debug.properties.get(1).faildToRead, true);
assertNotNull(debug.properties.get(1).readingException);
assertEquals(debug.properties.get(2).name, "anDouble");
assertEquals(debug.properties.get(2).type, OType.DOUBLE);
assertEquals(debug.properties.get(2).faildToRead, true);
assertNotNull(debug.properties.get(2).readingException);
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebug in project orientdb by orientechnologies.
the class ORecordSerializerBinaryDebugTest method testSimpleDocumentDebug.
@Test
public void testSimpleDocumentDebug() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + ORecordSerializerBinaryDebugTest.class.getSimpleName());
db.create();
try {
ODocument doc = new ODocument();
doc.field("test", "test");
doc.field("anInt", 2);
doc.field("anDouble", 2D);
byte[] bytes = doc.toStream();
ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug();
ORecordSerializationDebug debug = debugger.deserializeDebug(bytes, db);
assertEquals(debug.properties.size(), 3);
assertEquals(debug.properties.get(0).name, "test");
assertEquals(debug.properties.get(0).type, OType.STRING);
assertEquals(debug.properties.get(0).value, "test");
assertEquals(debug.properties.get(1).name, "anInt");
assertEquals(debug.properties.get(1).type, OType.INTEGER);
assertEquals(debug.properties.get(1).value, 2);
assertEquals(debug.properties.get(2).name, "anDouble");
assertEquals(debug.properties.get(2).type, OType.DOUBLE);
assertEquals(debug.properties.get(2).value, 2D);
} finally {
db.drop();
}
}
Aggregations