Skip to content

Commit

Permalink
Fixed #7470
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Jun 6, 2017
1 parent 22511f2 commit 2e9a3b2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.orientechnologies.orient.core.record.ORecordInternal;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.OEdgeDelegate;
import com.orientechnologies.orient.core.record.impl.ORecordBytes;
import com.orientechnologies.orient.core.record.impl.OVertexDelegate;
import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer;
import com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerNetworkV37;
Expand Down Expand Up @@ -339,9 +338,9 @@ static ORecord readRecordFromBytes(OChannelDataInput network, ORecordSerializer
final byte[] content = network.readBytes();

final ORecord record = Orient.instance().getRecordFactoryManager().newInstance(rec);
serializer.fromStream(content, record, null);
ORecordInternal.setIdentity(record, rid);
ORecordInternal.setVersion(record, version);
serializer.fromStream(content, record, null);
ORecordInternal.unsetDirty(record);
return record;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.orientechnologies.orient.client.remote;

import com.orientechnologies.orient.client.remote.message.MockChannel;
import com.orientechnologies.orient.client.remote.message.OMessageHelper;
import com.orientechnologies.orient.core.db.ODatabaseType;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.record.ridbag.ORidBag;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.record.ORecordInternal;
import com.orientechnologies.orient.core.record.impl.ODirtyManager;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ODocumentInternal;
import com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerNetworkFactory;
import org.junit.Test;

import java.io.IOException;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Created by Enrico Risa on 06/06/2017.
*/
public class OMessageHelperTest {

@Test
public void testOIdentifiable() throws IOException {

OrientDB orientDB = new OrientDB("embedded", OrientDBConfig.defaultConfig());

orientDB.create("testOIdentifiable", ODatabaseType.MEMORY);

ODatabaseDocument open = orientDB.open("testOIdentifiable", "admin", "admin");


try {
MockChannel channel = new MockChannel();
ODocument doc = new ODocument();
ORidBag bags = new ORidBag();
bags.add(new ORecordId(11,0));
doc.field("bag",bags );

ODocumentInternal.fillClassNameIfNeeded(doc, "Test");
ORecordInternal.setIdentity(doc, new ORecordId(10, 0));
ORecordInternal.setVersion(doc, 1);

OMessageHelper.writeIdentifiable(channel, doc, ORecordSerializerNetworkFactory.INSTANCE.current());
channel.close();

ODocument newDoc = (ODocument) OMessageHelper.readIdentifiable(channel, ORecordSerializerNetworkFactory.INSTANCE.current());

assertThat(newDoc.getClassName()).isEqualTo("Test");
assertThat((ORidBag) newDoc.field("bag")).hasSize(1);

ODirtyManager dirtyManager = ORecordInternal.getDirtyManager(newDoc);
assertThat(dirtyManager.getNewRecords()).isNull();

}finally {
orientDB.close();
}


}
}

0 comments on commit 2e9a3b2

Please sign in to comment.