From 17089992e24cd5419959d7b6c494b376df9f0838 Mon Sep 17 00:00:00 2001 From: Ivannikov Kirill Date: Wed, 2 Sep 2015 13:57:57 +0500 Subject: [PATCH] testPostIndexWithException listener test --- .../index/shard/IndexShardTests.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index c06480b31d7..b646c9b9ee2 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -654,4 +654,38 @@ public class IndexShardTests extends ESSingleNodeTestCase { assertTrue(listenerInfo.get("postIndexCalled")); } + public void testPostIndexWithException() throws IOException { + createIndex("testpostindexwithexception"); + ensureGreen(); + IndicesService indicesService = getInstanceFromNode(IndicesService.class); + IndexService test = indicesService.indexService("testpostindexwithexception"); + IndexShard shard = test.shard(0); + ShardIndexingService shardIndexingService = shard.indexingService(); + + shard.close("Unexpected close", true); + shard.state = IndexShardState.STARTED; // It will generate exception + + final HashMap listenerInfo = new HashMap<>(); + listenerInfo.put("postIndexWithExceptionCalled", false); + + shardIndexingService.addListener(new IndexingOperationListener() { + @Override + public void postIndex(Engine.Index index, Throwable ex) { + listenerInfo.put("postIndexWithExceptionCalled", true); + super.postIndex(index, ex); + } + }); + + 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); + + try { + shard.index(index); + }catch (IllegalIndexShardStateException e){ + + } + + assertTrue(listenerInfo.get("postIndexWithExceptionCalled")); + } + }