Skip to content

Commit 37bd8e9

Browse files
committed
test: corrected random failing of distributed unit test
1 parent 05312f6 commit 37bd8e9

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

distributed/src/test/java/com/orientechnologies/orient/server/distributed/impl/OTransactionPhase2TaskTest.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.orientechnologies.orient.core.record.OElement;
1313
import com.orientechnologies.orient.core.record.impl.ODocument;
1414
import com.orientechnologies.orient.core.tx.OTransactionId;
15+
import com.orientechnologies.orient.distributed.db.OrientDBDistributed;
1516
import com.orientechnologies.orient.server.OServer;
1617
import com.orientechnologies.orient.server.distributed.ODistributedRequestId;
1718
import com.orientechnologies.orient.server.distributed.impl.task.OTransactionPhase1Task;
@@ -47,35 +48,40 @@ public void before()
4748

4849
@Test
4950
public void testOkSecondPhase() throws Exception {
50-
OIdentifiable id = session.save(new ODocument("TestClass"));
51+
OElement element = session.save(new ODocument("TestClass"));
52+
ODatabaseDocumentInternal internal = (ODatabaseDocumentInternal) session;
53+
internal.getLocalCache().clear();
54+
ODistributedDatabaseImpl distributed =
55+
((OrientDBDistributed) server.getDatabases()).getDatabase(session.getName());
56+
57+
ORID id = element.getIdentity();
58+
int pre_version = element.getVersion();
5159
List<ORecordOperation> operations = new ArrayList<>();
52-
ODocument rec1 = new ODocument(id.getIdentity());
60+
ODocument rec1 = new ODocument(id);
5361
rec1.setClassName("TestClass");
5462
rec1.field("one", "two");
55-
5663
TreeSet<ORID> ids = new TreeSet<ORID>();
5764
ids.add(rec1.getIdentity());
5865
operations.add(new ORecordOperation(rec1, ORecordOperation.UPDATED));
5966
SortedSet<OTransactionUniqueKey> uniqueIndexKeys = new TreeSet<>();
60-
OTransactionId transactionId = new OTransactionId(Optional.empty(), 0, 1);
67+
OTransactionId transactionId = distributed.nextId().get();
6168
OTransactionPhase1Task task =
6269
new OTransactionPhase1Task(operations, transactionId, new TreeSet<>());
63-
task.execute(
64-
new ODistributedRequestId(10, 20), server, null, (ODatabaseDocumentInternal) session);
70+
ODistributedRequestId firstPhaseId = new ODistributedRequestId(10, 20);
71+
task.execute(firstPhaseId, server, null, internal);
6572
OTransactionPhase2Task task2 =
66-
new OTransactionPhase2Task(
67-
new ODistributedRequestId(10, 20), true, ids, uniqueIndexKeys, transactionId);
68-
task2.execute(
69-
new ODistributedRequestId(10, 21), server, null, (ODatabaseDocumentInternal) session);
73+
new OTransactionPhase2Task(firstPhaseId, true, ids, uniqueIndexKeys, transactionId);
74+
task2.execute(new ODistributedRequestId(10, 21), server, null, internal);
7075

71-
assertEquals(2, session.load(id.getIdentity()).getVersion());
76+
assertEquals(pre_version + 1, session.load(id).getVersion());
7277
}
7378

7479
@Test
7580
public void testSecondPhaseForcePromiseDespiteCompetingSuccessfulFirstPhase() throws Exception {
7681
ODatabaseDocumentInternal db = (ODatabaseDocumentInternal) session;
7782
OIdentifiable id = session.save(new ODocument("TestClass"));
78-
83+
ODistributedDatabaseImpl distributed =
84+
((OrientDBDistributed) server.getDatabases()).getDatabase(session.getName());
7985
OElement doc1 = db.load(id.getIdentity());
8086
doc1.setProperty("value", "1");
8187
List<ORecordOperation> doc1Ops = new ArrayList<>();
@@ -93,14 +99,14 @@ public void testSecondPhaseForcePromiseDespiteCompetingSuccessfulFirstPhase() th
9399
doc2UniqueIndexKeys.add(new OTransactionUniqueKey("TestClass.value", "2", doc2.getVersion()));
94100

95101
ODistributedRequestId tx1p1Id = new ODistributedRequestId(10, 20);
96-
OTransactionId tx1Id = new OTransactionId(Optional.empty(), 0, 1);
102+
OTransactionId tx1Id = distributed.nextId().get();
97103
OTransactionPhase1Task tx1p1 = new OTransactionPhase1Task(doc1Ops, tx1Id, doc1UniqueIndexKeys);
98104
OTransactionPhase1TaskResult tx1p1Result =
99105
(OTransactionPhase1TaskResult) tx1p1.execute(tx1p1Id, server, null, db);
100106
assertTrue(tx1p1Result.getResultPayload() instanceof OTxSuccess);
101107

102108
ODistributedRequestId tx2p1Id = new ODistributedRequestId(10, 21);
103-
OTransactionId tx2Id = new OTransactionId(Optional.empty(), 1, 1);
109+
OTransactionId tx2Id = distributed.nextId().get();
104110
OTransactionPhase1Task tx2p1 = new OTransactionPhase1Task(doc2Ops, tx2Id, doc2UniqueIndexKeys);
105111
OTransactionPhase1TaskResult tx2p1Result =
106112
(OTransactionPhase1TaskResult) tx2p1.execute(tx2p1Id, server, null, db);

0 commit comments

Comments
 (0)