11
11
12
12
package org .opensearch .knn .indices ;
13
13
14
- import org .junit .AfterClass ;
15
- import org .junit .Assert ;
16
- import org .junit .BeforeClass ;
14
+ import org .junit .*;
15
+ import org .mockito .MockedStatic ;
17
16
import org .opensearch .ExceptionsHelper ;
18
17
import org .opensearch .ResourceAlreadyExistsException ;
19
18
import org .opensearch .ResourceNotFoundException ;
19
+ import org .opensearch .cluster .ClusterChangedEvent ;
20
20
import org .opensearch .core .action .ActionListener ;
21
21
import org .opensearch .action .DocWriteResponse ;
22
22
import org .opensearch .action .StepListener ;
46
46
import org .opensearch .knn .plugin .transport .UpdateModelGraveyardAction ;
47
47
import org .opensearch .knn .plugin .transport .UpdateModelGraveyardRequest ;
48
48
import org .opensearch .core .rest .RestStatus ;
49
+ import org .opensearch .knn .training .TrainingJobClusterStateListener ;
49
50
50
51
import java .io .IOException ;
51
52
import java .time .ZoneOffset ;
57
58
import java .util .concurrent .Executors ;
58
59
import java .util .concurrent .TimeUnit ;
59
60
61
+ import static org .mockito .ArgumentMatchers .any ;
62
+ import static org .mockito .Mockito .*;
60
63
import static org .opensearch .cluster .metadata .Metadata .builder ;
61
64
import static org .opensearch .knn .common .KNNConstants .DIMENSION ;
62
65
import static org .opensearch .knn .common .KNNConstants .KNN_ENGINE ;
@@ -73,15 +76,21 @@ public class ModelDaoTests extends KNNSingleNodeTestCase {
73
76
74
77
private static ExecutorService modelGetterExecutor ;
75
78
private static final String FAILED = "failed" ;
79
+ private static MockedStatic <TrainingJobClusterStateListener > trainingJobClusterStateListenerMockedStatic ;
76
80
77
81
@ BeforeClass
78
82
public static void setup () {
79
83
modelGetterExecutor = Executors .newSingleThreadExecutor ();
84
+ trainingJobClusterStateListenerMockedStatic = mockStatic (TrainingJobClusterStateListener .class );
85
+ final TrainingJobClusterStateListener trainingJobClusterStateListener = mock (TrainingJobClusterStateListener .class );
86
+ doNothing ().when (trainingJobClusterStateListener ).clusterChanged (any (ClusterChangedEvent .class ));
87
+ trainingJobClusterStateListenerMockedStatic .when (TrainingJobClusterStateListener ::getInstance ).thenReturn (trainingJobClusterStateListener );
80
88
}
81
89
82
90
@ AfterClass
83
91
public static void teardown () {
84
92
modelGetterExecutor .shutdown ();
93
+ trainingJobClusterStateListenerMockedStatic .close ();
85
94
}
86
95
87
96
public void testCreate () throws IOException , InterruptedException {
0 commit comments