AtomicBoolean
This commit is contained in:
parent
17089992e2
commit
dbf42ba297
|
@ -78,6 +78,7 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.EMPTY_PARAMS;
|
import static org.elasticsearch.cluster.metadata.IndexMetaData.EMPTY_PARAMS;
|
||||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
||||||
|
@ -611,14 +612,12 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
||||||
IndexService test = indicesService.indexService("testpreindex");
|
IndexService test = indicesService.indexService("testpreindex");
|
||||||
IndexShard shard = test.shard(0);
|
IndexShard shard = test.shard(0);
|
||||||
ShardIndexingService shardIndexingService = shard.indexingService();
|
ShardIndexingService shardIndexingService = shard.indexingService();
|
||||||
|
final AtomicBoolean preIndexCalled = new AtomicBoolean(false);
|
||||||
final HashMap<String, Boolean> listenerInfo = new HashMap<>();
|
|
||||||
listenerInfo.put("preIndexCalled", false);
|
|
||||||
|
|
||||||
shardIndexingService.addListener(new IndexingOperationListener() {
|
shardIndexingService.addListener(new IndexingOperationListener() {
|
||||||
@Override
|
@Override
|
||||||
public Engine.Index preIndex(Engine.Index index) {
|
public Engine.Index preIndex(Engine.Index index) {
|
||||||
listenerInfo.put("preIndexCalled", true);
|
preIndexCalled.set(true);
|
||||||
return super.preIndex(index);
|
return super.preIndex(index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -626,7 +625,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
||||||
ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, new ParseContext.Document(), new BytesArray(new byte[]{1}), null);
|
ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, new ParseContext.Document(), new BytesArray(new byte[]{1}), null);
|
||||||
Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);
|
Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);
|
||||||
shard.index(index);
|
shard.index(index);
|
||||||
assertTrue(listenerInfo.get("preIndexCalled"));
|
assertTrue(preIndexCalled.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPostIndex() throws IOException {
|
public void testPostIndex() throws IOException {
|
||||||
|
@ -636,14 +635,12 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
||||||
IndexService test = indicesService.indexService("testpostindex");
|
IndexService test = indicesService.indexService("testpostindex");
|
||||||
IndexShard shard = test.shard(0);
|
IndexShard shard = test.shard(0);
|
||||||
ShardIndexingService shardIndexingService = shard.indexingService();
|
ShardIndexingService shardIndexingService = shard.indexingService();
|
||||||
|
final AtomicBoolean postIndexCalled = new AtomicBoolean(false);
|
||||||
final HashMap<String, Boolean> listenerInfo = new HashMap<>();
|
|
||||||
listenerInfo.put("postIndexCalled", false);
|
|
||||||
|
|
||||||
shardIndexingService.addListener(new IndexingOperationListener() {
|
shardIndexingService.addListener(new IndexingOperationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void postIndex(Engine.Index index) {
|
public void postIndex(Engine.Index index) {
|
||||||
listenerInfo.put("postIndexCalled", true);
|
postIndexCalled.set(true);
|
||||||
super.postIndex(index);
|
super.postIndex(index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -651,7 +648,7 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
||||||
ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, new ParseContext.Document(), new BytesArray(new byte[]{1}), null);
|
ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, new ParseContext.Document(), new BytesArray(new byte[]{1}), null);
|
||||||
Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);
|
Engine.Index index = new Engine.Index(new Term("_uid", "1"), doc);
|
||||||
shard.index(index);
|
shard.index(index);
|
||||||
assertTrue(listenerInfo.get("postIndexCalled"));
|
assertTrue(postIndexCalled.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPostIndexWithException() throws IOException {
|
public void testPostIndexWithException() throws IOException {
|
||||||
|
@ -665,13 +662,12 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
||||||
shard.close("Unexpected close", true);
|
shard.close("Unexpected close", true);
|
||||||
shard.state = IndexShardState.STARTED; // It will generate exception
|
shard.state = IndexShardState.STARTED; // It will generate exception
|
||||||
|
|
||||||
final HashMap<String, Boolean> listenerInfo = new HashMap<>();
|
final AtomicBoolean postIndexWithExceptionCalled = new AtomicBoolean(false);
|
||||||
listenerInfo.put("postIndexWithExceptionCalled", false);
|
|
||||||
|
|
||||||
shardIndexingService.addListener(new IndexingOperationListener() {
|
shardIndexingService.addListener(new IndexingOperationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void postIndex(Engine.Index index, Throwable ex) {
|
public void postIndex(Engine.Index index, Throwable ex) {
|
||||||
listenerInfo.put("postIndexWithExceptionCalled", true);
|
postIndexWithExceptionCalled.set(true);
|
||||||
super.postIndex(index, ex);
|
super.postIndex(index, ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -681,11 +677,12 @@ public class IndexShardTests extends ESSingleNodeTestCase {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
shard.index(index);
|
shard.index(index);
|
||||||
|
fail();
|
||||||
}catch (IllegalIndexShardStateException e){
|
}catch (IllegalIndexShardStateException e){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(listenerInfo.get("postIndexWithExceptionCalled"));
|
assertTrue(postIndexWithExceptionCalled.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue