|
36 | 36 | import io.spine.server.delivery.ShardSessionRecord; |
37 | 37 | import io.spine.server.delivery.ShardedWorkRegistry; |
38 | 38 | import io.spine.server.delivery.ShardedWorkRegistryTest; |
| 39 | +import io.spine.server.delivery.WorkerId; |
39 | 40 | import io.spine.testing.server.storage.datastore.TestDatastoreStorageFactory; |
40 | 41 | import org.junit.jupiter.api.AfterEach; |
41 | 42 | import org.junit.jupiter.api.BeforeEach; |
|
47 | 48 | import static com.google.common.truth.Truth.assertThat; |
48 | 49 | import static com.google.common.truth.Truth8.assertThat; |
49 | 50 | import static io.spine.server.storage.datastore.given.TestShardIndex.newIndex; |
50 | | -import static org.junit.Assert.assertFalse; |
51 | | -import static org.junit.Assert.assertTrue; |
52 | 51 |
|
53 | 52 | @DisplayName("`DsShardedWorkRegistry` should") |
54 | 53 | class DsShardedWorkRegistryTest extends ShardedWorkRegistryTest { |
@@ -82,60 +81,62 @@ protected ShardedWorkRegistry registry() { |
82 | 81 | @DisplayName("pick up the shard and write a corresponding record to the storage") |
83 | 82 | void pickUp() { |
84 | 83 | Optional<ShardProcessingSession> session = registry.pickUp(index, nodeId); |
85 | | - assertTrue(session.isPresent()); |
| 84 | + WorkerId expectedWorker = registry.currentWorkerFor(nodeId); |
| 85 | + assertThat(session).isPresent(); |
86 | 86 | assertThat(session.get() |
87 | 87 | .shardIndex()).isEqualTo(index); |
88 | 88 |
|
89 | 89 | ShardSessionRecord record = readSingleRecord(index); |
90 | 90 | assertThat(record.getIndex()).isEqualTo(index); |
91 | | - assertThat(record.getPickedBy()).isEqualTo(nodeId); |
| 91 | + assertThat(record.getWorker()).isEqualTo(expectedWorker); |
92 | 92 | } |
93 | 93 |
|
94 | 94 | @Test |
95 | 95 | @DisplayName("not be able to pick up the shard if it's already picked up") |
96 | 96 | void cannotPickUpIfTaken() { |
97 | 97 |
|
98 | 98 | Optional<ShardProcessingSession> session = registry.pickUp(index, nodeId); |
99 | | - assertTrue(session.isPresent()); |
| 99 | + assertThat(session).isPresent(); |
100 | 100 |
|
101 | 101 | Optional<ShardProcessingSession> sameIdxSameNode = registry.pickUp(index, nodeId); |
102 | | - assertFalse(sameIdxSameNode.isPresent()); |
| 102 | + assertThat(sameIdxSameNode).isEmpty(); |
103 | 103 |
|
104 | 104 | Optional<ShardProcessingSession> sameIdxAnotherNode = registry.pickUp(index, newNode()); |
105 | | - assertFalse(sameIdxAnotherNode.isPresent()); |
| 105 | + assertThat(sameIdxAnotherNode).isEmpty(); |
106 | 106 |
|
107 | 107 | ShardIndex anotherIdx = newIndex(24, 100); |
108 | 108 | Optional<ShardProcessingSession> anotherIdxSameNode = registry.pickUp(anotherIdx, nodeId); |
109 | | - assertTrue(anotherIdxSameNode.isPresent()); |
| 109 | + assertThat(anotherIdxSameNode).isPresent(); |
110 | 110 |
|
111 | 111 | Optional<ShardProcessingSession> anotherIdxAnotherNode = |
112 | 112 | registry.pickUp(anotherIdx, newNode()); |
113 | | - assertFalse(anotherIdxAnotherNode.isPresent()); |
| 113 | + assertThat(anotherIdxAnotherNode).isEmpty(); |
114 | 114 | } |
115 | 115 |
|
116 | 116 | @Test |
117 | 117 | @DisplayName("complete the shard session (once picked up) and make it available for picking up") |
118 | 118 | void completeSessionAndMakeItAvailable() { |
119 | 119 | Optional<ShardProcessingSession> optional = registry.pickUp(index, nodeId); |
120 | | - assertTrue(optional.isPresent()); |
| 120 | + assertThat(optional).isPresent(); |
121 | 121 |
|
122 | 122 | Timestamp whenPickedFirst = readSingleRecord(index).getWhenLastPicked(); |
123 | 123 |
|
124 | 124 | DsShardProcessingSession session = (DsShardProcessingSession) optional.get(); |
125 | 125 | session.complete(); |
126 | 126 |
|
127 | 127 | ShardSessionRecord completedRecord = readSingleRecord(index); |
128 | | - assertFalse(completedRecord.hasPickedBy()); |
| 128 | + assertThat(completedRecord.hasWorker()).isFalse(); |
129 | 129 |
|
130 | 130 | NodeId anotherNode = newNode(); |
| 131 | + WorkerId anotherWorker = registry.currentWorkerFor(anotherNode); |
131 | 132 | Optional<ShardProcessingSession> anotherOptional = registry.pickUp(index, anotherNode); |
132 | | - assertTrue(anotherOptional.isPresent()); |
| 133 | + assertThat(anotherOptional).isPresent(); |
133 | 134 |
|
134 | 135 | ShardSessionRecord secondSessionRecord = readSingleRecord(index); |
135 | | - assertThat(secondSessionRecord.getPickedBy()).isEqualTo(anotherNode); |
| 136 | + assertThat(secondSessionRecord.getWorker()).isEqualTo(anotherWorker); |
136 | 137 |
|
137 | 138 | Timestamp whenPickedSecond = secondSessionRecord.getWhenLastPicked(); |
138 | | - assertTrue(Timestamps.compare(whenPickedFirst, whenPickedSecond) < 0); |
| 139 | + assertThat(Timestamps.compare(whenPickedFirst, whenPickedSecond) < 0).isTrue(); |
139 | 140 | } |
140 | 141 |
|
141 | 142 | @Test |
|
0 commit comments