Skip to content

Commit f59e5cd

Browse files
authored
Simplify XPackLicenseState tests (#78484)
Tests for the license state historically test each feature at random license levels. But this is unnecessary because what really matters are the combinations of current license state and license level of a feature. This commit removes the dozens of feature specific tests in favor of simple tests for a feature of each license level, asserting whether that feature is allowed or not.
1 parent 329d596 commit f59e5cd

File tree

1 file changed

+50
-227
lines changed

1 file changed

+50
-227
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/license/XPackLicenseStateTests.java

Lines changed: 50 additions & 227 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.elasticsearch.license.License.OperationMode.BASIC;
2222
import static org.elasticsearch.license.License.OperationMode.ENTERPRISE;
2323
import static org.elasticsearch.license.License.OperationMode.GOLD;
24-
import static org.elasticsearch.license.License.OperationMode.MISSING;
2524
import static org.elasticsearch.license.License.OperationMode.PLATINUM;
2625
import static org.elasticsearch.license.License.OperationMode.STANDARD;
2726
import static org.elasticsearch.license.License.OperationMode.TRIAL;
@@ -201,171 +200,6 @@ public void testMonitoringAckNotBasicToBasic() {
201200
assertAckMessages(XPackField.MONITORING, from, BASIC, 2);
202201
}
203202

204-
public void testMonitoringUpdateRetention() {
205-
assertAllowed(STANDARD, true, s -> s.checkFeature(Feature.MONITORING_UPDATE_RETENTION), true);
206-
assertAllowed(GOLD, true, s -> s.checkFeature(Feature.MONITORING_UPDATE_RETENTION), true);
207-
assertAllowed(PLATINUM, true, s -> s.checkFeature(Feature.MONITORING_UPDATE_RETENTION), true);
208-
assertAllowed(TRIAL, true, s -> s.checkFeature(Feature.MONITORING_UPDATE_RETENTION), true);
209-
assertAllowed(BASIC, true, s -> s.checkFeature(Feature.MONITORING_UPDATE_RETENTION), false);
210-
assertAllowed(MISSING, false, s -> s.checkFeature(Feature.MONITORING_UPDATE_RETENTION), false);
211-
}
212-
213-
public void testWatcherPlatinumGoldTrialStandard() throws Exception {
214-
assertAllowed(TRIAL, true, s -> s.checkFeature(Feature.WATCHER), true);
215-
assertAllowed(GOLD, true, s -> s.checkFeature(Feature.WATCHER), true);
216-
assertAllowed(PLATINUM, true, s -> s.checkFeature(Feature.WATCHER), true);
217-
assertAllowed(STANDARD, true, s -> s.checkFeature(Feature.WATCHER), true);
218-
}
219-
220-
public void testWatcherBasicLicense() throws Exception {
221-
assertAllowed(BASIC, true, s -> s.checkFeature(Feature.WATCHER), false);
222-
}
223-
224-
public void testWatcherInactive() {
225-
assertAllowed(BASIC, false, s -> s.checkFeature(Feature.WATCHER), false);
226-
}
227-
228-
public void testWatcherInactivePlatinumGoldTrial() throws Exception {
229-
assertAllowed(TRIAL, false, s -> s.checkFeature(Feature.WATCHER), false);
230-
assertAllowed(GOLD, false, s -> s.checkFeature(Feature.WATCHER), false);
231-
assertAllowed(PLATINUM, false, s -> s.checkFeature(Feature.WATCHER), false);
232-
assertAllowed(STANDARD, false, s -> s.checkFeature(Feature.WATCHER), false);
233-
}
234-
235-
public void testEncryptedSnapshotsWithInactiveLicense() {
236-
assertAllowed(BASIC, false, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), false);
237-
assertAllowed(TRIAL, false, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), false);
238-
assertAllowed(GOLD, false, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), false);
239-
assertAllowed(PLATINUM, false, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), false);
240-
assertAllowed(ENTERPRISE, false, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), false);
241-
assertAllowed(STANDARD, false, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), false);
242-
}
243-
244-
public void testEncryptedSnapshotsWithActiveLicense() {
245-
assertAllowed(BASIC, true, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), false);
246-
assertAllowed(TRIAL, true, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), true);
247-
assertAllowed(GOLD, true, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), false);
248-
assertAllowed(PLATINUM, true, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), true);
249-
assertAllowed(ENTERPRISE, true, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), true);
250-
assertAllowed(STANDARD, true, s -> s.checkFeature(Feature.ENCRYPTED_SNAPSHOT), false);
251-
}
252-
253-
public void testGraphPlatinumTrial() throws Exception {
254-
assertAllowed(TRIAL, true, s -> s.checkFeature(Feature.GRAPH), true);
255-
assertAllowed(PLATINUM, true, s -> s.checkFeature(Feature.GRAPH), true);
256-
}
257-
258-
public void testGraphBasic() throws Exception {
259-
assertAllowed(BASIC, true, s -> s.checkFeature(Feature.GRAPH), false);
260-
}
261-
262-
public void testGraphStandard() throws Exception {
263-
assertAllowed(STANDARD, true, s -> s.checkFeature(Feature.GRAPH), false);
264-
}
265-
266-
public void testGraphInactiveBasic() {
267-
assertAllowed(BASIC, false, s -> s.checkFeature(Feature.GRAPH), false);
268-
}
269-
270-
public void testGraphInactivePlatinumTrial() throws Exception {
271-
assertAllowed(TRIAL, false, s -> s.checkFeature(Feature.MACHINE_LEARNING), false);
272-
assertAllowed(PLATINUM, false, s -> s.checkFeature(Feature.MACHINE_LEARNING), false);
273-
}
274-
275-
public void testMachineLearningPlatinumTrial() throws Exception {
276-
assertAllowed(TRIAL, true, s -> s.checkFeature(Feature.MACHINE_LEARNING), true);
277-
assertAllowed(PLATINUM, true, s -> s.checkFeature(Feature.MACHINE_LEARNING), true);
278-
}
279-
280-
public void testMachineLearningBasic() throws Exception {
281-
assertAllowed(BASIC, true, s -> s.checkFeature(Feature.MACHINE_LEARNING), false);
282-
}
283-
284-
public void testMachineLearningStandard() throws Exception {
285-
assertAllowed(STANDARD, true, s -> s.checkFeature(Feature.MACHINE_LEARNING), false);
286-
}
287-
288-
public void testMachineLearningInactiveBasic() {
289-
assertAllowed(BASIC, false, s -> s.checkFeature(Feature.MACHINE_LEARNING), false);
290-
}
291-
292-
public void testMachineLearningInactivePlatinumTrial() throws Exception {
293-
assertAllowed(TRIAL, false, s -> s.checkFeature(Feature.MACHINE_LEARNING), false);
294-
assertAllowed(PLATINUM, false, s -> s.checkFeature(Feature.MACHINE_LEARNING), false);
295-
}
296-
297-
public void testLogstashPlatinumGoldTrialStandard() throws Exception {
298-
assertAllowed(TRIAL, true, s -> s.checkFeature(Feature.LOGSTASH), true);
299-
assertAllowed(GOLD, true, s -> s.checkFeature(Feature.LOGSTASH), true);
300-
assertAllowed(PLATINUM, true, s -> s.checkFeature(Feature.LOGSTASH), true);
301-
assertAllowed(STANDARD, true, s -> s.checkFeature(Feature.LOGSTASH), true);
302-
}
303-
304-
public void testLogstashBasicLicense() throws Exception {
305-
assertAllowed(BASIC, true, s -> s.checkFeature(Feature.LOGSTASH), false);
306-
}
307-
308-
public void testLogstashInactive() {
309-
assertAllowed(BASIC, false, s -> s.checkFeature(Feature.LOGSTASH), false);
310-
assertAllowed(TRIAL, false, s -> s.checkFeature(Feature.LOGSTASH), false);
311-
assertAllowed(GOLD, false, s -> s.checkFeature(Feature.LOGSTASH), false);
312-
assertAllowed(PLATINUM, false, s -> s.checkFeature(Feature.LOGSTASH), false);
313-
assertAllowed(STANDARD, false, s -> s.checkFeature(Feature.LOGSTASH), false);
314-
}
315-
316-
public void testJdbcDefaults() {
317-
XPackLicenseState licenseState = TestUtils.newTestLicenseState();
318-
assertThat(licenseState.checkFeature(XPackLicenseState.Feature.JDBC), is(true));
319-
}
320-
321-
public void testJdbcBasic() {
322-
XPackLicenseState licenseState = TestUtils.newTestLicenseState();
323-
licenseState.update(BASIC, true, null);
324-
assertThat(licenseState.checkFeature(XPackLicenseState.Feature.JDBC), is(false));
325-
}
326-
327-
public void testJdbcStandard() {
328-
XPackLicenseState licenseState = TestUtils.newTestLicenseState();
329-
licenseState.update(STANDARD, true, null);
330-
331-
assertThat(licenseState.checkFeature(XPackLicenseState.Feature.JDBC), is(false));
332-
}
333-
334-
public void testJdbcStandardExpired() {
335-
XPackLicenseState licenseState = TestUtils.newTestLicenseState();
336-
licenseState.update(STANDARD, false, null);
337-
338-
assertThat(licenseState.checkFeature(XPackLicenseState.Feature.JDBC), is(false));
339-
}
340-
341-
public void testJdbcGold() {
342-
XPackLicenseState licenseState = TestUtils.newTestLicenseState();
343-
licenseState.update(GOLD, true, null);
344-
345-
assertThat(licenseState.checkFeature(XPackLicenseState.Feature.JDBC), is(false));
346-
}
347-
348-
public void testJdbcGoldExpired() {
349-
XPackLicenseState licenseState = TestUtils.newTestLicenseState();
350-
licenseState.update(GOLD, false, null);
351-
352-
assertThat(licenseState.checkFeature(XPackLicenseState.Feature.JDBC), is(false));
353-
}
354-
355-
public void testJdbcPlatinum() {
356-
XPackLicenseState licenseState = TestUtils.newTestLicenseState();
357-
licenseState.update(PLATINUM, true, null);
358-
359-
assertThat(licenseState.checkFeature(XPackLicenseState.Feature.JDBC), is(true));
360-
}
361-
362-
public void testJdbcPlatinumExpired() {
363-
XPackLicenseState licenseState = TestUtils.newTestLicenseState();
364-
licenseState.update(PLATINUM, false, null);
365-
366-
assertThat(licenseState.checkFeature(XPackLicenseState.Feature.JDBC), is(false));
367-
}
368-
369203
public void testSqlAckAnyToTrialOrPlatinum() {
370204
assertAckMessages(XPackField.SQL, randomMode(), randomTrialOrPlatinumMode(), 0);
371205
}
@@ -374,67 +208,6 @@ public void testSqlAckTrialOrPlatinumToNotTrialOrPlatinum() {
374208
assertAckMessages(XPackField.SQL, randomTrialOrPlatinumMode(), randomBasicStandardOrGold(), 1);
375209
}
376210

377-
public void testCcrDefaults() {
378-
final XPackLicenseState state = TestUtils.newTestLicenseState();
379-
assertTrue(state.checkFeature(XPackLicenseState.Feature.CCR));
380-
}
381-
382-
public void testCcrBasic() {
383-
final XPackLicenseState state = TestUtils.newTestLicenseState();
384-
state.update(BASIC, true, null);
385-
386-
assertThat(state.checkFeature(XPackLicenseState.Feature.CCR), is(false));
387-
}
388-
389-
public void testCcrBasicExpired() {
390-
final XPackLicenseState state = TestUtils.newTestLicenseState();
391-
state.update(BASIC, false, null);
392-
393-
assertThat(state.checkFeature(XPackLicenseState.Feature.CCR), is(false));
394-
}
395-
396-
public void testCcrStandard() {
397-
final XPackLicenseState state = TestUtils.newTestLicenseState();
398-
state.update(STANDARD, true, null);
399-
400-
assertThat(state.checkFeature(XPackLicenseState.Feature.CCR), is(false));
401-
}
402-
403-
public void testCcrStandardExpired() {
404-
final XPackLicenseState state = TestUtils.newTestLicenseState();
405-
state.update(STANDARD, false, null);
406-
407-
assertThat(state.checkFeature(XPackLicenseState.Feature.CCR), is(false));
408-
}
409-
410-
public void testCcrGold() {
411-
final XPackLicenseState state = TestUtils.newTestLicenseState();
412-
state.update(GOLD, true, null);
413-
414-
assertThat(state.checkFeature(XPackLicenseState.Feature.CCR), is(false));
415-
}
416-
417-
public void testCcrGoldExpired() {
418-
final XPackLicenseState state = TestUtils.newTestLicenseState();
419-
state.update(GOLD, false, null);
420-
421-
assertThat(state.checkFeature(XPackLicenseState.Feature.CCR), is(false));
422-
}
423-
424-
public void testCcrPlatinum() {
425-
final XPackLicenseState state = TestUtils.newTestLicenseState();
426-
state.update(PLATINUM, true, null);
427-
428-
assertTrue(state.checkFeature(XPackLicenseState.Feature.CCR));
429-
}
430-
431-
public void testCcrPlatinumExpired() {
432-
final XPackLicenseState state = TestUtils.newTestLicenseState();
433-
state.update(PLATINUM, false, null);
434-
435-
assertFalse(state.checkFeature(XPackLicenseState.Feature.CCR));
436-
}
437-
438211
public void testCcrAckAnyToTrialOrPlatinum() {
439212
assertAckMessages(XPackField.CCR, randomMode(), randomTrialOrPlatinumMode(), 0);
440213
}
@@ -443,6 +216,56 @@ public void testCcrAckTrialOrPlatinumToNotTrialOrPlatinum() {
443216
assertAckMessages(XPackField.CCR, randomTrialOrPlatinumMode(), randomBasicStandardOrGold(), 1);
444217
}
445218

219+
public void testExpiredLicense() {
220+
// use standard feature which would normally be allowed at all license levels
221+
LicensedFeature feature = LicensedFeature.momentary("family", "enterpriseFeature", STANDARD);
222+
assertAllowed(STANDARD, false, s -> s.isAllowed(feature), false);
223+
assertAllowed(GOLD, false, s -> s.isAllowed(feature), false);
224+
assertAllowed(PLATINUM, false, s -> s.isAllowed(feature), false);
225+
assertAllowed(ENTERPRISE, false, s -> s.isAllowed(feature), false);
226+
assertAllowed(TRIAL, false, s -> s.isAllowed(feature), false);
227+
}
228+
229+
public void testStandardFeature() {
230+
LicensedFeature feature = LicensedFeature.momentary("family", "standardFeature", STANDARD);
231+
assertAllowed(BASIC, true, s -> s.isAllowed(feature), false);
232+
assertAllowed(STANDARD, true, s -> s.isAllowed(feature), true);
233+
assertAllowed(GOLD, true, s -> s.isAllowed(feature), true);
234+
assertAllowed(PLATINUM, true, s -> s.isAllowed(feature), true);
235+
assertAllowed(ENTERPRISE, true, s -> s.isAllowed(feature), true);
236+
assertAllowed(TRIAL, true, s -> s.isAllowed(feature), true);
237+
}
238+
239+
public void testGoldFeature() {
240+
LicensedFeature feature = LicensedFeature.momentary("family", "goldFeature", GOLD);
241+
assertAllowed(BASIC, true, s -> s.isAllowed(feature), false);
242+
assertAllowed(STANDARD, true, s -> s.isAllowed(feature), false);
243+
assertAllowed(GOLD, true, s -> s.isAllowed(feature), true);
244+
assertAllowed(PLATINUM, true, s -> s.isAllowed(feature), true);
245+
assertAllowed(ENTERPRISE, true, s -> s.isAllowed(feature), true);
246+
assertAllowed(TRIAL, true, s -> s.isAllowed(feature), true);
247+
}
248+
249+
public void testPlatinumFeature() {
250+
LicensedFeature feature = LicensedFeature.momentary("family", "platinumFeature", PLATINUM);
251+
assertAllowed(BASIC, true, s -> s.isAllowed(feature), false);
252+
assertAllowed(STANDARD, true, s -> s.isAllowed(feature), false);
253+
assertAllowed(GOLD, true, s -> s.isAllowed(feature), false);
254+
assertAllowed(PLATINUM, true, s -> s.isAllowed(feature), true);
255+
assertAllowed(ENTERPRISE, true, s -> s.isAllowed(feature), true);
256+
assertAllowed(TRIAL, true, s -> s.isAllowed(feature), true);
257+
}
258+
259+
public void testEnterpriseFeature() {
260+
LicensedFeature feature = LicensedFeature.momentary("family", "enterpriseFeature", ENTERPRISE);
261+
assertAllowed(BASIC, true, s -> s.isAllowed(feature), false);
262+
assertAllowed(STANDARD, true, s -> s.isAllowed(feature), false);
263+
assertAllowed(GOLD, true, s -> s.isAllowed(feature), false);
264+
assertAllowed(PLATINUM, true, s -> s.isAllowed(feature), false);
265+
assertAllowed(ENTERPRISE, true, s -> s.isAllowed(feature), true);
266+
assertAllowed(TRIAL, true, s -> s.isAllowed(feature), true);
267+
}
268+
446269
public void testLastUsedMomentaryFeature() {
447270
LicensedFeature.Momentary goldFeature = LicensedFeature.momentary("family", "goldFeature", GOLD);
448271
AtomicInteger currentTime = new AtomicInteger(100); // non zero start time

0 commit comments

Comments
 (0)