1818import org .elasticsearch .indices .IndicesService ;
1919import org .elasticsearch .plugins .Plugin ;
2020import org .elasticsearch .test .ESIntegTestCase ;
21+ import org .junit .After ;
2122
2223import java .util .Collection ;
2324import java .util .List ;
2425
2526import static org .elasticsearch .xpack .gpu .TestVectorsFormatUtils .randomGPUSupportedSimilarity ;
2627import static org .hamcrest .Matchers .containsString ;
28+ import static org .hamcrest .Matchers .equalTo ;
2729import static org .hamcrest .Matchers .startsWith ;
2830
2931public class GPUPluginInitializationWithGPUIT extends ESIntegTestCase {
3032
3133 static {
32- TestCuVSServiceProvider .mockedGPUInfoProvider = SUPPORTEp -> new TestCuVSServiceProvider .TestGPUInfoProvider (
34+ TestCuVSServiceProvider .mockedGPUInfoProvider = p -> new TestCuVSServiceProvider .TestGPUInfoProvider (
3335 List .of (
3436 new GPUInfo (
3537 0 ,
@@ -44,15 +46,34 @@ public class GPUPluginInitializationWithGPUIT extends ESIntegTestCase {
4446 );
4547 }
4648
49+ private static boolean isGpuIndexingFeatureAllowed = true ;
50+
51+ public static class TestGPUPlugin extends GPUPlugin {
52+
53+ public TestGPUPlugin () {
54+ super ();
55+ }
56+
57+ @ Override
58+ protected boolean isGpuIndexingFeatureAllowed () {
59+ return GPUPluginInitializationWithGPUIT .isGpuIndexingFeatureAllowed ;
60+ }
61+ }
62+
63+ @ After
64+ public void reset () {
65+ isGpuIndexingFeatureAllowed = true ;
66+ }
67+
4768 @ Override
4869 protected Collection <Class <? extends Plugin >> nodePlugins () {
49- return List .of (GPUPlugin .class );
70+ return List .of (TestGPUPlugin .class );
5071 }
5172
5273 public void testFFOff () {
5374 assumeFalse ("GPU_FORMAT feature flag disabled" , GPUPlugin .GPU_FORMAT .isEnabled ());
5475
55- GPUPlugin gpuPlugin = internalCluster ().getInstance (GPUPlugin .class );
76+ GPUPlugin gpuPlugin = internalCluster ().getInstance (TestGPUPlugin .class );
5677 VectorsFormatProvider vectorsFormatProvider = gpuPlugin .getVectorsFormatProvider ();
5778
5879 var format = vectorsFormatProvider .getKnnVectorsFormat (null , null , null );
@@ -74,7 +95,7 @@ public void testFFOffIndexSettingNotSupported() {
7495 public void testFFOffGPUFormatNull () {
7596 assumeFalse ("GPU_FORMAT feature flag disabled" , GPUPlugin .GPU_FORMAT .isEnabled ());
7697
77- GPUPlugin gpuPlugin = internalCluster ().getInstance (GPUPlugin .class );
98+ GPUPlugin gpuPlugin = internalCluster ().getInstance (TestGPUPlugin .class );
7899 VectorsFormatProvider vectorsFormatProvider = gpuPlugin .getVectorsFormatProvider ();
79100
80101 createIndex ("index1" , Settings .EMPTY );
@@ -89,10 +110,10 @@ public void testFFOffGPUFormatNull() {
89110 assertNull (format );
90111 }
91112
92- public void testIndexSettingOnIndexTypeSupportedGPUSupported () {
113+ public void testIndexSettingOnIndexAllSupported () {
93114 assumeTrue ("GPU_FORMAT feature flag enabled" , GPUPlugin .GPU_FORMAT .isEnabled ());
94115
95- GPUPlugin gpuPlugin = internalCluster ().getInstance (GPUPlugin .class );
116+ GPUPlugin gpuPlugin = internalCluster ().getInstance (TestGPUPlugin .class );
96117 VectorsFormatProvider vectorsFormatProvider = gpuPlugin .getVectorsFormatProvider ();
97118
98119 createIndex ("index1" , Settings .builder ().put (GPUPlugin .VECTORS_INDEXING_USE_GPU_SETTING .getKey (), GPUPlugin .GpuMode .TRUE ).build ());
@@ -110,7 +131,7 @@ public void testIndexSettingOnIndexTypeSupportedGPUSupported() {
110131 public void testIndexSettingOnIndexTypeNotSupportedThrows () {
111132 assumeTrue ("GPU_FORMAT feature flag enabled" , GPUPlugin .GPU_FORMAT .isEnabled ());
112133
113- GPUPlugin gpuPlugin = internalCluster ().getInstance (GPUPlugin .class );
134+ GPUPlugin gpuPlugin = internalCluster ().getInstance (TestGPUPlugin .class );
114135 VectorsFormatProvider vectorsFormatProvider = gpuPlugin .getVectorsFormatProvider ();
115136
116137 createIndex ("index1" , Settings .builder ().put (GPUPlugin .VECTORS_INDEXING_USE_GPU_SETTING .getKey (), GPUPlugin .GpuMode .TRUE ).build ());
@@ -124,10 +145,31 @@ public void testIndexSettingOnIndexTypeNotSupportedThrows() {
124145 assertThat (ex .getMessage (), startsWith ("[index.vectors.indexing.use_gpu] doesn't support [index_options.type] of" ));
125146 }
126147
127- public void testIndexSettingAutoIndexTypeSupportedGPUSupported () {
148+ public void testIndexSettingOnIndexLicenseNotSupportedThrows () {
149+ assumeTrue ("GPU_FORMAT feature flag enabled" , GPUPlugin .GPU_FORMAT .isEnabled ());
150+ isGpuIndexingFeatureAllowed = false ;
151+
152+ GPUPlugin gpuPlugin = internalCluster ().getInstance (TestGPUPlugin .class );
153+ VectorsFormatProvider vectorsFormatProvider = gpuPlugin .getVectorsFormatProvider ();
154+
155+ createIndex ("index1" , Settings .builder ().put (GPUPlugin .VECTORS_INDEXING_USE_GPU_SETTING .getKey (), GPUPlugin .GpuMode .TRUE ).build ());
156+ IndexSettings settings = getIndexSettings ();
157+ final var indexOptions = DenseVectorFieldTypeTests .randomGpuSupportedIndexOptions ();
158+
159+ var ex = expectThrows (
160+ IllegalArgumentException .class ,
161+ () -> vectorsFormatProvider .getKnnVectorsFormat (settings , indexOptions , randomGPUSupportedSimilarity (indexOptions .getType ()))
162+ );
163+ assertThat (
164+ ex .getMessage (),
165+ equalTo ("[index.vectors.indexing.use_gpu] was set to [true], but GPU indexing is a [ENTERPRISE] level feature" )
166+ );
167+ }
168+
169+ public void testIndexSettingAutoAllSupported () {
128170 assumeTrue ("GPU_FORMAT feature flag enabled" , GPUPlugin .GPU_FORMAT .isEnabled ());
129171
130- GPUPlugin gpuPlugin = internalCluster ().getInstance (GPUPlugin .class );
172+ GPUPlugin gpuPlugin = internalCluster ().getInstance (TestGPUPlugin .class );
131173 VectorsFormatProvider vectorsFormatProvider = gpuPlugin .getVectorsFormatProvider ();
132174
133175 createIndex ("index1" , Settings .builder ().put (GPUPlugin .VECTORS_INDEXING_USE_GPU_SETTING .getKey (), GPUPlugin .GpuMode .AUTO ).build ());
@@ -142,10 +184,29 @@ public void testIndexSettingAutoIndexTypeSupportedGPUSupported() {
142184 assertNotNull (format );
143185 }
144186
187+ public void testIndexSettingAutoLicenseNotSupported () {
188+ assumeTrue ("GPU_FORMAT feature flag enabled" , GPUPlugin .GPU_FORMAT .isEnabled ());
189+ isGpuIndexingFeatureAllowed = false ;
190+
191+ GPUPlugin gpuPlugin = internalCluster ().getInstance (TestGPUPlugin .class );
192+ VectorsFormatProvider vectorsFormatProvider = gpuPlugin .getVectorsFormatProvider ();
193+
194+ createIndex ("index1" , Settings .builder ().put (GPUPlugin .VECTORS_INDEXING_USE_GPU_SETTING .getKey (), GPUPlugin .GpuMode .AUTO ).build ());
195+ IndexSettings settings = getIndexSettings ();
196+ final var indexOptions = DenseVectorFieldTypeTests .randomGpuSupportedIndexOptions ();
197+
198+ var format = vectorsFormatProvider .getKnnVectorsFormat (
199+ settings ,
200+ indexOptions ,
201+ randomGPUSupportedSimilarity (indexOptions .getType ())
202+ );
203+ assertNull (format );
204+ }
205+
145206 public void testIndexSettingAutoIndexTypeNotSupported () {
146207 assumeTrue ("GPU_FORMAT feature flag enabled" , GPUPlugin .GPU_FORMAT .isEnabled ());
147208
148- GPUPlugin gpuPlugin = internalCluster ().getInstance (GPUPlugin .class );
209+ GPUPlugin gpuPlugin = internalCluster ().getInstance (TestGPUPlugin .class );
149210 VectorsFormatProvider vectorsFormatProvider = gpuPlugin .getVectorsFormatProvider ();
150211
151212 createIndex ("index1" , Settings .builder ().put (GPUPlugin .VECTORS_INDEXING_USE_GPU_SETTING .getKey (), GPUPlugin .GpuMode .AUTO ).build ());
@@ -163,7 +224,7 @@ public void testIndexSettingAutoIndexTypeNotSupported() {
163224 public void testIndexSettingOff () {
164225 assumeTrue ("GPU_FORMAT feature flag enabled" , GPUPlugin .GPU_FORMAT .isEnabled ());
165226
166- GPUPlugin gpuPlugin = internalCluster ().getInstance (GPUPlugin .class );
227+ GPUPlugin gpuPlugin = internalCluster ().getInstance (TestGPUPlugin .class );
167228 VectorsFormatProvider vectorsFormatProvider = gpuPlugin .getVectorsFormatProvider ();
168229
169230 createIndex ("index1" , Settings .builder ().put (GPUPlugin .VECTORS_INDEXING_USE_GPU_SETTING .getKey (), GPUPlugin .GpuMode .FALSE ).build ());
0 commit comments