cleanup unit tests
Original commit: elastic/x-pack-elasticsearch@f759f45b7f
This commit is contained in:
parent
0e39df71f6
commit
3c5fca12ba
|
@ -18,6 +18,8 @@ import org.elasticsearch.license.core.License;
|
|||
import org.elasticsearch.license.plugin.TestUtils;
|
||||
import org.elasticsearch.transport.EmptyTransportResponseHandler;
|
||||
import org.elasticsearch.transport.TransportRequest;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
|
@ -29,11 +31,23 @@ import static org.mockito.Mockito.verify;
|
|||
|
||||
public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase {
|
||||
|
||||
public void testNotificationOnNewLicense() throws Exception {
|
||||
private TestUtils.AssertingLicensee licensee;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
setInitialState(null);
|
||||
licensesService.start();
|
||||
final TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee("testNotificationOnNewLicense", logger);
|
||||
licensee = new TestUtils.AssertingLicensee("LicenseClusterChangeTests", logger);
|
||||
licensesService.register(licensee);
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
licensesService.stop();
|
||||
}
|
||||
|
||||
|
||||
public void testNotificationOnNewLicense() throws Exception {
|
||||
ClusterState oldState = ClusterState.builder(new ClusterName("a")).build();
|
||||
final License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(24));
|
||||
MetaData metaData = MetaData.builder().putCustom(LicensesMetaData.TYPE, new LicensesMetaData(license)).build();
|
||||
|
@ -41,28 +55,18 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase {
|
|||
licensesService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState));
|
||||
assertThat(licensee.statuses.size(), equalTo(1));
|
||||
assertTrue(licensee.statuses.get(0).getLicenseState() == LicenseState.ENABLED);
|
||||
licensesService.stop();
|
||||
}
|
||||
|
||||
public void testNoNotificationOnExistingLicense() throws Exception {
|
||||
setInitialState(null);
|
||||
licensesService.start();
|
||||
final TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee("testNoNotificationOnExistingLicense", logger);
|
||||
licensesService.register(licensee);
|
||||
final License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(24));
|
||||
MetaData metaData = MetaData.builder().putCustom(LicensesMetaData.TYPE, new LicensesMetaData(license)).build();
|
||||
ClusterState newState = ClusterState.builder(new ClusterName("a")).metaData(metaData).build();
|
||||
ClusterState oldState = ClusterState.builder(newState).build();
|
||||
licensesService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState));
|
||||
assertThat(licensee.statuses.size(), equalTo(0));
|
||||
licensesService.stop();
|
||||
}
|
||||
|
||||
public void testTrialLicenseGeneration() throws Exception {
|
||||
setInitialState(null);
|
||||
licensesService.start();
|
||||
final TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee("testNotificationOnNewLicense", logger);
|
||||
licensesService.register(licensee);
|
||||
DiscoveryNode master = new DiscoveryNode("b", DummyTransportAddress.INSTANCE, emptyMap(), emptySet(), Version.CURRENT);
|
||||
ClusterState oldState = ClusterState.builder(new ClusterName("a"))
|
||||
.nodes(DiscoveryNodes.builder().masterNodeId(master.getId()).put(master)).build();
|
||||
|
@ -72,6 +76,5 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase {
|
|||
.sendRequest(any(DiscoveryNode.class),
|
||||
eq(LicensesService.REGISTER_TRIAL_LICENSE_ACTION_NAME),
|
||||
any(TransportRequest.Empty.class), any(EmptyTransportResponseHandler.class));
|
||||
licensesService.stop();
|
||||
}
|
||||
}
|
|
@ -9,22 +9,28 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.TestUtils;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class LicenseScheduleTests extends ESTestCase {
|
||||
|
||||
private License license;
|
||||
private LicenseSchedule schedule;
|
||||
|
||||
@Before
|
||||
public void setuo() throws Exception {
|
||||
license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(12));
|
||||
schedule = new LicenseSchedule(license);
|
||||
}
|
||||
|
||||
public void testEnabledLicenseSchedule() throws Exception {
|
||||
License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(12));
|
||||
final LicenseSchedule schedule = new LicenseSchedule(license);
|
||||
int expiryDuration = (int) (license.expiryDate() - license.issueDate());
|
||||
long triggeredTime = license.issueDate() + between(0, expiryDuration);
|
||||
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime), equalTo(license.expiryDate()));
|
||||
}
|
||||
|
||||
public void testGraceLicenseSchedule() throws Exception {
|
||||
License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(12));
|
||||
final LicenseSchedule schedule = new LicenseSchedule(license);
|
||||
long triggeredTime = license.expiryDate() + between(1,
|
||||
((int) LicensesService.GRACE_PERIOD_DURATION.getMillis()));
|
||||
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
|
||||
|
@ -32,8 +38,6 @@ public class LicenseScheduleTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testExpiredLicenseSchedule() throws Exception {
|
||||
License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(12));
|
||||
final LicenseSchedule schedule = new LicenseSchedule(license);
|
||||
long triggeredTime = license.expiryDate() + LicensesService.GRACE_PERIOD_DURATION.getMillis() +
|
||||
randomIntBetween(1, 1000);
|
||||
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
|
||||
|
@ -41,8 +45,6 @@ public class LicenseScheduleTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testInvalidLicenseSchedule() throws Exception {
|
||||
License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(12));
|
||||
final LicenseSchedule schedule = new LicenseSchedule(license);
|
||||
long triggeredTime = license.issueDate() - randomIntBetween(1, 1000);
|
||||
assertThat(schedule.nextScheduledTimeAfter(triggeredTime, triggeredTime),
|
||||
equalTo(license.issueDate()));
|
||||
|
|
|
@ -7,17 +7,16 @@ package org.elasticsearch.license.plugin.core;
|
|||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.graph.Graph;
|
||||
import org.elasticsearch.xpack.graph.Graph;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.TestUtils;
|
||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
||||
import org.elasticsearch.marvel.Monitoring;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.shield.Security;
|
||||
import org.elasticsearch.xpack.security.Security;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.watcher.Watcher;
|
||||
|
@ -194,7 +193,7 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
public void onFailure(Exception throwable) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue