Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontedor committed Jul 4, 2017
1 parent 93e751f commit e8e4544
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void testClosesPreventsNewOperations() throws InterruptedException, Execu
// expected
}
try {
indexShard.acquireReplicaOperationPermit(indexShard.getPrimaryTerm(), SequenceNumbersService.UNASSIGNED_SEQ_NO, null,
indexShard.acquireReplicaOperationPermit(indexShard.getPrimaryTerm(), SequenceNumbersService.NO_OPS_PERFORMED, null,
ThreadPool.Names.INDEX);
fail("we should not be able to increment anymore");
} catch (IndexShardClosedException e) {
Expand All @@ -287,7 +287,7 @@ public void testRejectOperationPermitWithHigherTermWhenNotStarted() throws IOExc
IndexShard indexShard = newShard(false);
expectThrows(IndexShardNotStartedException.class, () ->
indexShard.acquireReplicaOperationPermit(indexShard.getPrimaryTerm() + randomIntBetween(1, 100),
SequenceNumbersService.UNASSIGNED_SEQ_NO, null, ThreadPool.Names.INDEX));
SequenceNumbersService.NO_OPS_PERFORMED, null, ThreadPool.Names.INDEX));
closeShards(indexShard);
}

Expand Down Expand Up @@ -509,6 +509,7 @@ public void testOperationPermitOnReplicaShards() throws Exception {
case 0:
// started replica
indexShard = newStartedShard(false);
indexShard.updateGlobalCheckpointOnReplica(SequenceNumbersService.NO_OPS_PERFORMED);
engineClosed = false;
break;
case 1: {
Expand All @@ -530,6 +531,9 @@ public void testOperationPermitOnReplicaShards() throws Exception {
routing = TestShardRouting.newShardRouting(routing.shardId(), routing.currentNodeId(), "otherNode",
true, ShardRoutingState.RELOCATING, AllocationId.newRelocation(routing.allocationId()));
IndexShardTestCase.updateRoutingEntry(indexShard, routing);
indexShard.updateLocalCheckpointForShard(
indexShard.routingEntry().allocationId().getId(),
SequenceNumbersService.NO_OPS_PERFORMED);
indexShard.relocated("test", primaryContext -> {});
engineClosed = false;
break;
Expand Down Expand Up @@ -580,7 +584,7 @@ public void onFailure(Exception e) {
}
};

indexShard.acquireReplicaOperationPermit(primaryTerm - 1, SequenceNumbersService.UNASSIGNED_SEQ_NO, onLockAcquired,
indexShard.acquireReplicaOperationPermit(primaryTerm - 1, SequenceNumbersService.NO_OPS_PERFORMED, onLockAcquired,
ThreadPool.Names.INDEX);

assertFalse(onResponse.get());
Expand All @@ -597,11 +601,11 @@ public void onFailure(Exception e) {
final long newPrimaryTerm = primaryTerm + 1 + randomInt(20);
if (engineClosed == false) {
assertThat(indexShard.getLocalCheckpoint(), equalTo(SequenceNumbersService.NO_OPS_PERFORMED));
assertThat(indexShard.getGlobalCheckpoint(), equalTo(SequenceNumbersService.UNASSIGNED_SEQ_NO));
assertThat(indexShard.getGlobalCheckpoint(), equalTo(SequenceNumbersService.NO_OPS_PERFORMED));
}
final long newGlobalCheckPoint;
if (engineClosed || randomBoolean()) {
newGlobalCheckPoint = SequenceNumbersService.UNASSIGNED_SEQ_NO;
newGlobalCheckPoint = SequenceNumbersService.NO_OPS_PERFORMED;
} else {
long localCheckPoint = indexShard.getGlobalCheckpoint() + randomInt(100);
// advance local checkpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,13 @@ protected void recoveryShardFromStore(IndexShard primary) throws IOException {
}

public static void updateRoutingEntry(IndexShard shard, ShardRouting shardRouting) throws IOException {
shard.updateShardState(shardRouting, shard.getPrimaryTerm(), null, 0L, Collections.emptySet(), Collections.emptySet());
final Set<String> activeAllocationIds;
if (shardRouting.primary()) {
activeAllocationIds = Collections.singleton(shardRouting.allocationId().getId());
} else {
activeAllocationIds = Collections.emptySet();
}
shard.updateShardState(shardRouting, shard.getPrimaryTerm(), null, 0L, activeAllocationIds, Collections.emptySet());
}

protected void recoveryEmptyReplica(IndexShard replica) throws IOException {
Expand Down

0 comments on commit e8e4544

Please sign in to comment.