Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test case for coordinated transaction begin, with relative refact…
…or for rid allocations
- Loading branch information
Showing
7 changed files
with
112 additions
and
50 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...entechnologies/orient/server/distributed/impl/coordinator/transaction/OMockAllocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.orientechnologies.orient.server.distributed.impl.coordinator.transaction; | ||
|
||
import com.orientechnologies.orient.server.distributed.impl.coordinator.OClusterPositionAllocator; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class OMockAllocator implements OClusterPositionAllocator { | ||
//Just Test not really need to be concurrent. | ||
private Map<Integer, AtomicLong> allocator = new HashMap<>(); | ||
|
||
@Override | ||
public long allocate(int clusterId) { | ||
AtomicLong counter = allocator.get(clusterId); | ||
if (counter == null) { | ||
counter = new AtomicLong(0); | ||
allocator.put(clusterId, counter); | ||
} | ||
return counter.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...s/orient/server/distributed/impl/coordinator/transaction/OSubmitTransactionBeginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.orientechnologies.orient.server.distributed.impl.coordinator.transaction; | ||
|
||
import com.orientechnologies.orient.core.db.record.ORecordOperation; | ||
import com.orientechnologies.orient.core.id.ORecordId; | ||
import com.orientechnologies.orient.core.record.impl.ODocument; | ||
import com.orientechnologies.orient.server.distributed.impl.coordinator.*; | ||
import com.orientechnologies.orient.server.distributed.impl.coordinator.mocktx.CoordinatorTxTest; | ||
import com.orientechnologies.orient.server.distributed.impl.coordinator.mocktx.OSubmitTx; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class OSubmitTransactionBeginTest { | ||
|
||
@Test | ||
public void testBegin() throws InterruptedException { | ||
ODistributedCoordinator coordinator = new ODistributedCoordinator(Executors.newSingleThreadExecutor(), new MockOperationLog(), | ||
new ODistributedLockManagerImpl(0), new OMockAllocator()); | ||
|
||
MockChannel cOne = new MockChannel(); | ||
ODistributedMember mOne = new ODistributedMember("one", cOne); | ||
coordinator.join(mOne); | ||
|
||
MockChannel cTwo = new MockChannel(); | ||
ODistributedMember mTwo = new ODistributedMember("two", cTwo); | ||
coordinator.join(mTwo); | ||
|
||
MockChannel cThree = new MockChannel(); | ||
ODistributedMember mThree = new ODistributedMember("three", cThree); | ||
coordinator.join(mThree); | ||
|
||
ArrayList<ORecordOperation> recordOps = new ArrayList<>(); | ||
ORecordOperation op = new ORecordOperation(new ORecordId(10, 10), ORecordOperation.CREATED); | ||
op.setRecord(new ODocument("aaaa")); | ||
recordOps.add(op); | ||
coordinator.submit(mOne, new OTransactionSubmit(new OSessionOperationId(), recordOps, new ArrayList<>())); | ||
assertTrue(cOne.sentRequest.await(1, TimeUnit.SECONDS)); | ||
assertTrue(cTwo.sentRequest.await(1, TimeUnit.SECONDS)); | ||
assertTrue(cThree.sentRequest.await(1, TimeUnit.SECONDS)); | ||
} | ||
|
||
private class MockChannel implements ODistributedChannel { | ||
private CountDownLatch sentRequest = new CountDownLatch(1); | ||
|
||
@Override | ||
public void sendRequest(OLogId id, ONodeRequest nodeRequest) { | ||
sentRequest.countDown(); | ||
} | ||
|
||
@Override | ||
public void sendResponse(OLogId id, ONodeResponse nodeResponse) { | ||
|
||
} | ||
|
||
@Override | ||
public void reply(OSubmitResponse response) { | ||
|
||
} | ||
} | ||
} |