|
7 | 7 |
|
8 | 8 | import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
9 | 9 | import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
|
| 10 | +import org.elasticsearch.action.delete.DeleteResponse; |
| 11 | +import org.elasticsearch.action.index.IndexResponse; |
10 | 12 | import org.elasticsearch.action.support.PlainActionFuture;
|
11 |
| -import org.elasticsearch.cluster.metadata.IndexMetadata; |
| 13 | +import org.elasticsearch.action.support.master.AcknowledgedResponse; |
| 14 | +import org.elasticsearch.action.update.UpdateResponse; |
12 | 15 | import org.elasticsearch.cluster.service.ClusterService;
|
13 | 16 | import org.elasticsearch.common.settings.Settings;
|
14 | 17 | import org.elasticsearch.common.util.concurrent.ThreadContext;
|
| 18 | +import org.elasticsearch.tasks.TaskId; |
15 | 19 | import org.elasticsearch.test.ESSingleNodeTestCase;
|
16 | 20 | import org.elasticsearch.transport.TransportService;
|
17 | 21 | import org.elasticsearch.xpack.core.search.action.AsyncSearchResponse;
|
|
21 | 25 |
|
22 | 26 | import java.io.IOException;
|
23 | 27 | import java.util.Collections;
|
24 |
| -import java.util.concurrent.ExecutionException; |
25 | 28 |
|
26 | 29 | // TODO: test CRUD operations
|
27 | 30 | public class AsyncTaskServiceTests extends ESSingleNodeTestCase {
|
@@ -95,14 +98,55 @@ public void testEnsuredAuthenticatedUserIsSame() throws IOException {
|
95 | 98 | assertFalse(indexService.ensureAuthenticatedUserIsSame(threadContext.getHeaders(), runAsDiffType));
|
96 | 99 | }
|
97 | 100 |
|
98 |
| - public void testSettings() throws ExecutionException, InterruptedException { |
99 |
| - PlainActionFuture<Void> future = PlainActionFuture.newFuture(); |
100 |
| - indexService.createIndexIfNecessary(future); |
101 |
| - future.get(); |
| 101 | + public void testAutoCreateIndex() throws Exception { |
| 102 | + { |
| 103 | + PlainActionFuture<Void> future = PlainActionFuture.newFuture(); |
| 104 | + indexService.createIndexIfNecessary(future); |
| 105 | + future.get(); |
| 106 | + assertSettings(); |
| 107 | + } |
| 108 | + AcknowledgedResponse ack = client().admin().indices().prepareDelete(index).get(); |
| 109 | + assertTrue(ack.isAcknowledged()); |
| 110 | + |
| 111 | + AsyncExecutionId id = new AsyncExecutionId("0", new TaskId("N/A", 0)); |
| 112 | + AsyncSearchResponse resp = new AsyncSearchResponse(id.getEncoded(), true, true, 0L, 0L); |
| 113 | + { |
| 114 | + PlainActionFuture<IndexResponse> future = PlainActionFuture.newFuture(); |
| 115 | + indexService.createResponse(id.getDocId(), Collections.emptyMap(), resp, future); |
| 116 | + future.get(); |
| 117 | + assertSettings(); |
| 118 | + } |
| 119 | + ack = client().admin().indices().prepareDelete(index).get(); |
| 120 | + assertTrue(ack.isAcknowledged()); |
| 121 | + { |
| 122 | + PlainActionFuture<DeleteResponse> future = PlainActionFuture.newFuture(); |
| 123 | + indexService.deleteResponse(id, future); |
| 124 | + future.get(); |
| 125 | + assertSettings(); |
| 126 | + } |
| 127 | + ack = client().admin().indices().prepareDelete(index).get(); |
| 128 | + assertTrue(ack.isAcknowledged()); |
| 129 | + { |
| 130 | + PlainActionFuture<UpdateResponse> future = PlainActionFuture.newFuture(); |
| 131 | + indexService.updateResponse(id.getDocId(), Collections.emptyMap(), resp, future); |
| 132 | + expectThrows(Exception.class, () -> future.get()); |
| 133 | + assertSettings(); |
| 134 | + } |
| 135 | + ack = client().admin().indices().prepareDelete(index).get(); |
| 136 | + assertTrue(ack.isAcknowledged()); |
| 137 | + { |
| 138 | + PlainActionFuture<UpdateResponse> future = PlainActionFuture.newFuture(); |
| 139 | + indexService.updateExpirationTime("0", 10L, future); |
| 140 | + expectThrows(Exception.class, () -> future.get()); |
| 141 | + assertSettings(); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + private void assertSettings() throws IOException { |
102 | 146 | GetIndexResponse getIndexResponse = client().admin().indices().getIndex(
|
103 | 147 | new GetIndexRequest().indices(index)).actionGet();
|
104 | 148 | Settings settings = getIndexResponse.getSettings().get(index);
|
105 |
| - assertEquals("1", settings.get(IndexMetadata.SETTING_NUMBER_OF_SHARDS)); |
106 |
| - assertEquals("0-1", settings.get(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS)); |
| 149 | + Settings expected = AsyncTaskIndexService.settings(); |
| 150 | + assertEquals(expected, settings.filter(key -> expected.hasValue(key))); |
107 | 151 | }
|
108 | 152 | }
|
0 commit comments