46
46
import org .opensearch .ml .common .transport .batch .MLBatchIngestionInput ;
47
47
import org .opensearch .ml .common .transport .batch .MLBatchIngestionRequest ;
48
48
import org .opensearch .ml .common .transport .batch .MLBatchIngestionResponse ;
49
+ import org .opensearch .ml .settings .MLFeatureEnabledSetting ;
49
50
import org .opensearch .ml .task .MLTaskManager ;
50
51
import org .opensearch .tasks .Task ;
51
52
import org .opensearch .test .OpenSearchTestCase ;
@@ -73,6 +74,8 @@ public class TransportBatchIngestionActionTests extends OpenSearchTestCase {
73
74
ThreadPool threadPool ;
74
75
@ Mock
75
76
ExecutorService executorService ;
77
+ @ Mock
78
+ private MLFeatureEnabledSetting mlFeatureEnabledSetting ;
76
79
77
80
private TransportBatchIngestionAction batchAction ;
78
81
private MLBatchIngestionInput batchInput ;
@@ -81,7 +84,14 @@ public class TransportBatchIngestionActionTests extends OpenSearchTestCase {
81
84
@ Before
82
85
public void setup () {
83
86
MockitoAnnotations .openMocks (this );
84
- batchAction = new TransportBatchIngestionAction (transportService , actionFilters , client , mlTaskManager , threadPool );
87
+ batchAction = new TransportBatchIngestionAction (
88
+ transportService ,
89
+ actionFilters ,
90
+ client ,
91
+ mlTaskManager ,
92
+ threadPool ,
93
+ mlFeatureEnabledSetting
94
+ );
85
95
86
96
Map <String , Object > fieldMap = new HashMap <>();
87
97
fieldMap .put ("chapter" , "$.content[0]" );
@@ -106,6 +116,8 @@ public void setup() {
106
116
.dataSources (dataSource )
107
117
.build ();
108
118
when (mlBatchIngestionRequest .getMlBatchIngestionInput ()).thenReturn (batchInput );
119
+
120
+ when (mlFeatureEnabledSetting .isOfflineBatchIngestionEnabled ()).thenReturn (true );
109
121
}
110
122
111
123
public void test_doExecute_success () {
@@ -181,6 +193,18 @@ public void test_doExecute_handleSuccessRate0() {
181
193
);
182
194
}
183
195
196
+ public void test_doExecute_batchIngestionDisabled () {
197
+ when (mlFeatureEnabledSetting .isOfflineBatchIngestionEnabled ()).thenReturn (false );
198
+ batchAction .doExecute (task , mlBatchIngestionRequest , actionListener );
199
+
200
+ ArgumentCaptor <IllegalStateException > argumentCaptor = ArgumentCaptor .forClass (IllegalStateException .class );
201
+ verify (actionListener ).onFailure (argumentCaptor .capture ());
202
+ assertEquals (
203
+ "Offline batch ingestion is currently disabled. To enable it, update the setting \" plugins.ml_commons.offline_batch_ingestion_enabled\" to true." ,
204
+ argumentCaptor .getValue ().getMessage ()
205
+ );
206
+ }
207
+
184
208
public void test_doExecute_noDataSource () {
185
209
MLBatchIngestionInput batchInput = MLBatchIngestionInput
186
210
.builder ()
0 commit comments