|
15 | 15 | import org.elasticsearch.client.IndicesAdminClient;
|
16 | 16 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
17 | 17 | import org.elasticsearch.protocol.xpack.frozen.FreezeRequest;
|
| 18 | +import org.elasticsearch.protocol.xpack.frozen.FreezeResponse; |
18 | 19 | import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction;
|
19 | 20 | import org.elasticsearch.xpack.core.ilm.Step.StepKey;
|
20 | 21 | import org.junit.Before;
|
@@ -86,7 +87,7 @@ public void testFreeze() {
|
86 | 87 | assertNotNull(request);
|
87 | 88 | assertEquals(1, request.indices().length);
|
88 | 89 | assertEquals(indexMetaData.getIndex().getName(), request.indices()[0]);
|
89 |
| - listener.onResponse(null); |
| 90 | + listener.onResponse(new FreezeResponse(true, true)); |
90 | 91 | return null;
|
91 | 92 | }).when(indicesClient).execute(Mockito.any(), Mockito.any(), Mockito.any());
|
92 | 93 |
|
@@ -151,4 +152,38 @@ public void onFailure(Exception e) {
|
151 | 152 |
|
152 | 153 | assertThat(exceptionThrown.get(), equalTo(true));
|
153 | 154 | }
|
| 155 | + |
| 156 | + public void testNotAcknowledged() { |
| 157 | + IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT)) |
| 158 | + .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); |
| 159 | + |
| 160 | + AdminClient adminClient = Mockito.mock(AdminClient.class); |
| 161 | + IndicesAdminClient indicesClient = Mockito.mock(IndicesAdminClient.class); |
| 162 | + |
| 163 | + Mockito.when(client.admin()).thenReturn(adminClient); |
| 164 | + Mockito.when(adminClient.indices()).thenReturn(indicesClient); |
| 165 | + Mockito.doAnswer(invocation -> { |
| 166 | + @SuppressWarnings("unchecked") |
| 167 | + ActionListener<AcknowledgedResponse> listener = (ActionListener<AcknowledgedResponse>) invocation.getArguments()[2]; |
| 168 | + listener.onResponse(new FreezeResponse(false, false)); |
| 169 | + return null; |
| 170 | + }).when(indicesClient).execute(Mockito.any(), Mockito.any(), Mockito.any()); |
| 171 | + |
| 172 | + SetOnce<Boolean> exceptionThrown = new SetOnce<>(); |
| 173 | + FreezeStep step = createRandomInstance(); |
| 174 | + step.performAction(indexMetaData, null, null, new AsyncActionStep.Listener() { |
| 175 | + @Override |
| 176 | + public void onResponse(boolean complete) { |
| 177 | + throw new AssertionError("Unexpected method call"); |
| 178 | + } |
| 179 | + |
| 180 | + @Override |
| 181 | + public void onFailure(Exception e) { |
| 182 | + assertEquals("freeze index request failed to be acknowledged", e.getMessage()); |
| 183 | + exceptionThrown.set(true); |
| 184 | + } |
| 185 | + }); |
| 186 | + |
| 187 | + assertThat(exceptionThrown.get(), equalTo(true)); |
| 188 | + } |
154 | 189 | }
|
0 commit comments