awaitfix integ license expiry and grace notification tests

Original commit: elastic/x-pack-elasticsearch@bb03eb0e73
This commit is contained in:
Areek Zillur 2016-06-01 16:48:50 -04:00
parent c9a7052133
commit 42b8d33ea7
3 changed files with 24 additions and 6 deletions

View File

@ -120,6 +120,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
assertLazyConsumerPluginNotification(LicenseState.ENABLED, 5);
}
@AwaitsFix(bugUrl = "todo fix test using mock clock")
public void testClusterRestartWhileGrace() throws Exception {
wipeAllLicenses();
internalCluster().startNode();
@ -134,6 +135,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
assertLazyConsumerPluginNotification(LicenseState.GRACE_PERIOD, 5);
}
@AwaitsFix(bugUrl = "todo fix test using mock clock")
public void testClusterRestartWhileExpired() throws Exception {
wipeAllLicenses();
internalCluster().startNode();

View File

@ -31,6 +31,7 @@ import java.util.Collection;
import java.util.Collections;
import static org.elasticsearch.license.plugin.TestUtils.dateMath;
import static org.elasticsearch.license.plugin.TestUtils.generateExpiredLicense;
import static org.elasticsearch.license.plugin.TestUtils.generateSignedLicense;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
@ -129,7 +130,7 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
}
public void testPutExpiredLicense() throws Exception {
License expiredLicense = generateSignedLicense(dateMath("now-10d/d", System.currentTimeMillis()), TimeValue.timeValueMinutes(2));
License expiredLicense = generateExpiredLicense();
PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE);
builder.setLicense(expiredLicense);
PutLicenseResponse putLicenseResponse = builder.get();
@ -162,7 +163,7 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
License goldLicense = generateSignedLicense("gold", TimeValue.timeValueMinutes(5));
PutLicenseRequestBuilder putLicenseRequestBuilder =
new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(goldLicense)
.setAcknowledge(true);
.setAcknowledge(true);
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
@ -177,4 +178,4 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster(), GetLicenseAction.INSTANCE).get();
assertNull(getLicenseResponse.license());
}
}
}

View File

@ -29,6 +29,7 @@ import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.license.plugin.core.LicensesStatus;
import org.junit.Assert;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;
@ -91,7 +92,7 @@ public class TestUtils {
}
public static License generateSignedLicense(String type, long issueDate, TimeValue expiryDuration) throws Exception {
long issue = (issueDate != -1L) ? issueDate : System.currentTimeMillis();
long issue = (issueDate != -1L) ? issueDate : System.currentTimeMillis() - TimeValue.timeValueHours(2).getMillis();
int version = randomIntBetween(License.VERSION_START, License.VERSION_CURRENT);
final String licenseType;
if (version < License.VERSION_NO_FEATURE_TYPE) {
@ -102,7 +103,7 @@ public class TestUtils {
final License.Builder builder = License.builder()
.uid(UUID.randomUUID().toString())
.version(version)
.expiryDate(issue + expiryDuration.getMillis())
.expiryDate(System.currentTimeMillis() + expiryDuration.getMillis())
.issueDate(issue)
.type(licenseType)
.issuedTo("customer")
@ -116,6 +117,20 @@ public class TestUtils {
return signer.sign(builder.build());
}
public static License generateExpiredLicense() throws Exception {
final License.Builder builder = License.builder()
.uid(UUID.randomUUID().toString())
.version(License.VERSION_CURRENT)
.expiryDate(System.currentTimeMillis() - TimeValue.timeValueHours(randomIntBetween(1, 10)).getMillis())
.issueDate(System.currentTimeMillis())
.type(randomFrom("basic", "silver", "dev", "gold", "platinum"))
.issuedTo("customer")
.issuer("elasticsearch")
.maxNodes(5);
LicenseSigner signer = new LicenseSigner(getTestPriKeyPath(), getTestPubKeyPath());
return signer.sign(builder.build());
}
private static Path getResourcePath(String resource) throws Exception {
return PathUtils.get(TestUtils.class.getResource(resource).toURI());
}
@ -199,4 +214,4 @@ public class TestUtils {
statuses.add(status);
}
}
}
}