6
6
package org .elasticsearch .xpack .ml .process ;
7
7
8
8
import com .carrotsearch .randomizedtesting .annotations .Timeout ;
9
- import org .elasticsearch .action .ActionFuture ;
10
9
import org .elasticsearch .action .bulk .BulkRequest ;
11
10
import org .elasticsearch .action .bulk .BulkResponse ;
12
- import org .elasticsearch .client .Client ;
13
11
import org .elasticsearch .common .bytes .BytesReference ;
14
12
import org .elasticsearch .common .settings .Settings ;
15
13
import org .elasticsearch .common .util .concurrent .ThreadContext ;
16
14
import org .elasticsearch .mock .orig .Mockito ;
17
15
import org .elasticsearch .test .ESTestCase ;
18
16
import org .elasticsearch .threadpool .ThreadPool ;
17
+ import org .elasticsearch .xpack .ml .notifications .AnomalyDetectionAuditor ;
18
+ import org .elasticsearch .xpack .ml .utils .persistence .ResultsPersisterService ;
19
19
import org .junit .After ;
20
20
import org .junit .Before ;
21
21
import org .mockito .ArgumentCaptor ;
@@ -54,24 +54,22 @@ public class IndexingStateProcessorTests extends ESTestCase {
54
54
private static final int NUM_LARGE_DOCS = 2 ;
55
55
private static final int LARGE_DOC_SIZE = 1000000 ;
56
56
57
- private Client client ;
58
57
private IndexingStateProcessor stateProcessor ;
58
+ private ResultsPersisterService resultsPersisterService ;
59
59
60
60
@ Before
61
- public void initialize () throws IOException {
62
- client = mock (Client .class );
63
- @ SuppressWarnings ("unchecked" )
64
- ActionFuture <BulkResponse > bulkResponseFuture = mock (ActionFuture .class );
65
- stateProcessor = spy (new IndexingStateProcessor (client , JOB_ID ));
66
- when (client .bulk (any (BulkRequest .class ))).thenReturn (bulkResponseFuture );
61
+ public void initialize () {
62
+ resultsPersisterService = mock (ResultsPersisterService .class );
63
+ AnomalyDetectionAuditor auditor = mock (AnomalyDetectionAuditor .class );
64
+ stateProcessor = spy (new IndexingStateProcessor (JOB_ID , resultsPersisterService , auditor ));
65
+ when (resultsPersisterService .bulkIndexWithRetry (any (BulkRequest .class ), any (), any (), any ())).thenReturn (mock (BulkResponse .class ));
67
66
ThreadPool threadPool = mock (ThreadPool .class );
68
- when (client .threadPool ()).thenReturn (threadPool );
69
67
when (threadPool .getThreadContext ()).thenReturn (new ThreadContext (Settings .EMPTY ));
70
68
}
71
69
72
70
@ After
73
71
public void verifyNoMoreClientInteractions () {
74
- Mockito .verifyNoMoreInteractions (client );
72
+ Mockito .verifyNoMoreInteractions (resultsPersisterService );
75
73
}
76
74
77
75
public void testStateRead () throws IOException {
@@ -85,8 +83,7 @@ public void testStateRead() throws IOException {
85
83
assertEquals (threeStates [0 ], capturedBytes .get (0 ).utf8ToString ());
86
84
assertEquals (threeStates [1 ], capturedBytes .get (1 ).utf8ToString ());
87
85
assertEquals (threeStates [2 ], capturedBytes .get (2 ).utf8ToString ());
88
- verify (client , times (3 )).bulk (any (BulkRequest .class ));
89
- verify (client , times (3 )).threadPool ();
86
+ verify (resultsPersisterService , times (3 )).bulkIndexWithRetry (any (BulkRequest .class ), any (), any (), any ());
90
87
}
91
88
92
89
public void testStateReadGivenConsecutiveZeroBytes () throws IOException {
@@ -96,7 +93,7 @@ public void testStateReadGivenConsecutiveZeroBytes() throws IOException {
96
93
stateProcessor .process (stream );
97
94
98
95
verify (stateProcessor , never ()).persist (any ());
99
- Mockito .verifyNoMoreInteractions (client );
96
+ Mockito .verifyNoMoreInteractions (resultsPersisterService );
100
97
}
101
98
102
99
public void testStateReadGivenConsecutiveSpacesFollowedByZeroByte () throws IOException {
@@ -106,7 +103,7 @@ public void testStateReadGivenConsecutiveSpacesFollowedByZeroByte() throws IOExc
106
103
stateProcessor .process (stream );
107
104
108
105
verify (stateProcessor , times (1 )).persist (any ());
109
- Mockito .verifyNoMoreInteractions (client );
106
+ Mockito .verifyNoMoreInteractions (resultsPersisterService );
110
107
}
111
108
112
109
/**
@@ -128,7 +125,6 @@ public void testLargeStateRead() throws Exception {
128
125
ByteArrayInputStream stream = new ByteArrayInputStream (builder .toString ().getBytes (StandardCharsets .UTF_8 ));
129
126
stateProcessor .process (stream );
130
127
verify (stateProcessor , times (NUM_LARGE_DOCS )).persist (any ());
131
- verify (client , times (NUM_LARGE_DOCS )).bulk (any (BulkRequest .class ));
132
- verify (client , times (NUM_LARGE_DOCS )).threadPool ();
128
+ verify (resultsPersisterService , times (NUM_LARGE_DOCS )).bulkIndexWithRetry (any (BulkRequest .class ), any (), any (), any ());
133
129
}
134
130
}
0 commit comments