12
12
import com .orientechnologies .orient .core .record .OElement ;
13
13
import com .orientechnologies .orient .core .record .impl .ODocument ;
14
14
import com .orientechnologies .orient .core .tx .OTransactionId ;
15
+ import com .orientechnologies .orient .distributed .db .OrientDBDistributed ;
15
16
import com .orientechnologies .orient .server .OServer ;
16
17
import com .orientechnologies .orient .server .distributed .ODistributedRequestId ;
17
18
import com .orientechnologies .orient .server .distributed .impl .task .OTransactionPhase1Task ;
@@ -47,35 +48,40 @@ public void before()
47
48
48
49
@ Test
49
50
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 ();
51
59
List <ORecordOperation > operations = new ArrayList <>();
52
- ODocument rec1 = new ODocument (id . getIdentity () );
60
+ ODocument rec1 = new ODocument (id );
53
61
rec1 .setClassName ("TestClass" );
54
62
rec1 .field ("one" , "two" );
55
-
56
63
TreeSet <ORID > ids = new TreeSet <ORID >();
57
64
ids .add (rec1 .getIdentity ());
58
65
operations .add (new ORecordOperation (rec1 , ORecordOperation .UPDATED ));
59
66
SortedSet <OTransactionUniqueKey > uniqueIndexKeys = new TreeSet <>();
60
- OTransactionId transactionId = new OTransactionId ( Optional . empty (), 0 , 1 );
67
+ OTransactionId transactionId = distributed . nextId (). get ( );
61
68
OTransactionPhase1Task task =
62
69
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 );
65
72
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 );
70
75
71
- assertEquals (2 , session .load (id . getIdentity () ).getVersion ());
76
+ assertEquals (pre_version + 1 , session .load (id ).getVersion ());
72
77
}
73
78
74
79
@ Test
75
80
public void testSecondPhaseForcePromiseDespiteCompetingSuccessfulFirstPhase () throws Exception {
76
81
ODatabaseDocumentInternal db = (ODatabaseDocumentInternal ) session ;
77
82
OIdentifiable id = session .save (new ODocument ("TestClass" ));
78
-
83
+ ODistributedDatabaseImpl distributed =
84
+ ((OrientDBDistributed ) server .getDatabases ()).getDatabase (session .getName ());
79
85
OElement doc1 = db .load (id .getIdentity ());
80
86
doc1 .setProperty ("value" , "1" );
81
87
List <ORecordOperation > doc1Ops = new ArrayList <>();
@@ -93,14 +99,14 @@ public void testSecondPhaseForcePromiseDespiteCompetingSuccessfulFirstPhase() th
93
99
doc2UniqueIndexKeys .add (new OTransactionUniqueKey ("TestClass.value" , "2" , doc2 .getVersion ()));
94
100
95
101
ODistributedRequestId tx1p1Id = new ODistributedRequestId (10 , 20 );
96
- OTransactionId tx1Id = new OTransactionId ( Optional . empty (), 0 , 1 );
102
+ OTransactionId tx1Id = distributed . nextId (). get ( );
97
103
OTransactionPhase1Task tx1p1 = new OTransactionPhase1Task (doc1Ops , tx1Id , doc1UniqueIndexKeys );
98
104
OTransactionPhase1TaskResult tx1p1Result =
99
105
(OTransactionPhase1TaskResult ) tx1p1 .execute (tx1p1Id , server , null , db );
100
106
assertTrue (tx1p1Result .getResultPayload () instanceof OTxSuccess );
101
107
102
108
ODistributedRequestId tx2p1Id = new ODistributedRequestId (10 , 21 );
103
- OTransactionId tx2Id = new OTransactionId ( Optional . empty (), 1 , 1 );
109
+ OTransactionId tx2Id = distributed . nextId (). get ( );
104
110
OTransactionPhase1Task tx2p1 = new OTransactionPhase1Task (doc2Ops , tx2Id , doc2UniqueIndexKeys );
105
111
OTransactionPhase1TaskResult tx2p1Result =
106
112
(OTransactionPhase1TaskResult ) tx2p1 .execute (tx2p1Id , server , null , db );
0 commit comments