|
@@ -0,0 +1,78 @@
|
|
|
+/*
|
|
|
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
+ * or more contributor license agreements. Licensed under the Elastic License;
|
|
|
+ * you may not use this file except in compliance with the Elastic License.
|
|
|
+ */
|
|
|
+package org.elasticsearch.xpack.vectors;
|
|
|
+
|
|
|
+import org.elasticsearch.action.support.ActionFilters;
|
|
|
+import org.elasticsearch.action.support.PlainActionFuture;
|
|
|
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
+import org.elasticsearch.common.settings.Settings;
|
|
|
+import org.elasticsearch.license.XPackLicenseState;
|
|
|
+import org.elasticsearch.test.ESTestCase;
|
|
|
+import org.elasticsearch.transport.TransportService;
|
|
|
+import org.elasticsearch.xpack.core.XPackFeatureSet;
|
|
|
+import org.elasticsearch.xpack.core.action.XPackUsageFeatureResponse;
|
|
|
+import org.elasticsearch.xpack.core.vectors.VectorsFeatureSetUsage;
|
|
|
+import org.junit.Before;
|
|
|
+
|
|
|
+import static org.hamcrest.core.Is.is;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+public class VectorsFeatureSetTests extends ESTestCase {
|
|
|
+
|
|
|
+ private XPackLicenseState licenseState;
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void init() {
|
|
|
+ licenseState = mock(XPackLicenseState.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testAvailable() throws Exception {
|
|
|
+ VectorsFeatureSet featureSet = new VectorsFeatureSet(Settings.EMPTY, licenseState);
|
|
|
+ boolean available = randomBoolean();
|
|
|
+ when(licenseState.isVectorsAllowed()).thenReturn(available);
|
|
|
+ assertThat(featureSet.available(), is(available));
|
|
|
+
|
|
|
+ var usageAction = new VectorsFeatureSet.UsageTransportAction(mock(TransportService.class), null, null,
|
|
|
+ mock(ActionFilters.class), null, Settings.EMPTY, licenseState);
|
|
|
+ PlainActionFuture<XPackUsageFeatureResponse> future = new PlainActionFuture<>();
|
|
|
+ usageAction.masterOperation(null, null, future);
|
|
|
+ XPackFeatureSet.Usage usage = future.get().getUsage();
|
|
|
+ assertThat(usage.available(), is(available));
|
|
|
+
|
|
|
+ BytesStreamOutput out = new BytesStreamOutput();
|
|
|
+ usage.writeTo(out);
|
|
|
+ XPackFeatureSet.Usage serializedUsage = new VectorsFeatureSetUsage(out.bytes().streamInput());
|
|
|
+ assertThat(serializedUsage.available(), is(available));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testEnabled() throws Exception {
|
|
|
+ boolean enabled = randomBoolean();
|
|
|
+ Settings.Builder settings = Settings.builder();
|
|
|
+ if (enabled) {
|
|
|
+ if (randomBoolean()) {
|
|
|
+ settings.put("xpack.vectors.enabled", enabled);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ settings.put("xpack.vectors.enabled", enabled);
|
|
|
+ }
|
|
|
+ VectorsFeatureSet featureSet = new VectorsFeatureSet(settings.build(), licenseState);
|
|
|
+ assertThat(featureSet.enabled(), is(enabled));
|
|
|
+
|
|
|
+ VectorsFeatureSet.UsageTransportAction usageAction = new VectorsFeatureSet.UsageTransportAction(mock(TransportService.class),
|
|
|
+ null, null, mock(ActionFilters.class), null, settings.build(), licenseState);
|
|
|
+ PlainActionFuture<XPackUsageFeatureResponse> future = new PlainActionFuture<>();
|
|
|
+ usageAction.masterOperation(null, null, future);
|
|
|
+ XPackFeatureSet.Usage usage = future.get().getUsage();
|
|
|
+ assertThat(usage.enabled(), is(enabled));
|
|
|
+
|
|
|
+ BytesStreamOutput out = new BytesStreamOutput();
|
|
|
+ usage.writeTo(out);
|
|
|
+ XPackFeatureSet.Usage serializedUsage = new VectorsFeatureSetUsage(out.bytes().streamInput());
|
|
|
+ assertThat(serializedUsage.enabled(), is(enabled));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|