[TEST] Ensure shard lock is acquired before we try the timeout version
This commit is contained in:
parent
ecfe72ebcc
commit
78fc7c3f01
|
@ -25,11 +25,9 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||||
import org.elasticsearch.common.util.concurrent.CountDown;
|
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.shard.ShardId;
|
import org.elasticsearch.index.shard.ShardId;
|
||||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -150,7 +148,6 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestLogging("env:TRACE")
|
|
||||||
public void testDeleteSafe() throws IOException, InterruptedException {
|
public void testDeleteSafe() throws IOException, InterruptedException {
|
||||||
final NodeEnvironment env = newNodeEnvironment();
|
final NodeEnvironment env = newNodeEnvironment();
|
||||||
ShardLock fooLock = env.shardLock(new ShardId("foo", 1));
|
ShardLock fooLock = env.shardLock(new ShardId("foo", 1));
|
||||||
|
@ -196,6 +193,8 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase {
|
||||||
|
|
||||||
final AtomicReference<Throwable> threadException = new AtomicReference<>();
|
final AtomicReference<Throwable> threadException = new AtomicReference<>();
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
final CountDownLatch blockLatch = new CountDownLatch(1);
|
||||||
|
final CountDownLatch start = new CountDownLatch(1);
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
Thread t = new Thread(new AbstractRunnable() {
|
Thread t = new Thread(new AbstractRunnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -203,12 +202,15 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase {
|
||||||
logger.error("unexpected error", t);
|
logger.error("unexpected error", t);
|
||||||
threadException.set(t);
|
threadException.set(t);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
blockLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doRun() throws Exception {
|
protected void doRun() throws Exception {
|
||||||
try (ShardLock fooLock = env.shardLock(new ShardId("foo", 1))) {
|
start.await();
|
||||||
Thread.sleep(100);
|
try (ShardLock _ = env.shardLock(new ShardId("foo", 1))) {
|
||||||
|
blockLatch.countDown();
|
||||||
|
Thread.sleep(randomIntBetween(1, 10));
|
||||||
}
|
}
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
|
@ -216,7 +218,10 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase {
|
||||||
t.start();
|
t.start();
|
||||||
} else {
|
} else {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
blockLatch.countDown();
|
||||||
}
|
}
|
||||||
|
start.countDown();
|
||||||
|
blockLatch.await();
|
||||||
|
|
||||||
env.deleteIndexDirectorySafe(new Index("foo"), 5000, idxSettings);
|
env.deleteIndexDirectorySafe(new Index("foo"), 5000, idxSettings);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue