Update tests.
This commit is contained in:
parent
fa96789a2b
commit
14d72c7603
1 changed files with 132 additions and 3 deletions
|
|
@ -40,6 +40,12 @@ public class KinesisClientLibConfiguratorTest {
|
||||||
"com.amazonaws.services.kinesis.clientlibrary.config.KinesisClientLibConfiguratorTest$AlwaysSucceedCredentialsProvider";
|
"com.amazonaws.services.kinesis.clientlibrary.config.KinesisClientLibConfiguratorTest$AlwaysSucceedCredentialsProvider";
|
||||||
private String credentialName2 =
|
private String credentialName2 =
|
||||||
"com.amazonaws.services.kinesis.clientlibrary.config.KinesisClientLibConfiguratorTest$AlwaysFailCredentialsProvider";
|
"com.amazonaws.services.kinesis.clientlibrary.config.KinesisClientLibConfiguratorTest$AlwaysFailCredentialsProvider";
|
||||||
|
private String credentialNameKinesis =
|
||||||
|
"com.amazonaws.services.kinesis.clientlibrary.config.KinesisClientLibConfiguratorTest$AlwaysSucceedCredentialsProviderKinesis";
|
||||||
|
private String credentialNameDynamoDB =
|
||||||
|
"com.amazonaws.services.kinesis.clientlibrary.config.KinesisClientLibConfiguratorTest$AlwaysSucceedCredentialsProviderDynamoDB";
|
||||||
|
private String credentialNameCloudWatch =
|
||||||
|
"com.amazonaws.services.kinesis.clientlibrary.config.KinesisClientLibConfiguratorTest$AlwaysSucceedCredentialsProviderCloudWatch";
|
||||||
private KinesisClientLibConfigurator configurator = new KinesisClientLibConfigurator();
|
private KinesisClientLibConfigurator configurator = new KinesisClientLibConfigurator();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -334,7 +340,39 @@ public class KinesisClientLibConfiguratorTest {
|
||||||
String test = StringUtils.join(new String[] {
|
String test = StringUtils.join(new String[] {
|
||||||
"streamName = a",
|
"streamName = a",
|
||||||
"applicationName = b",
|
"applicationName = b",
|
||||||
"AWSCredentialsProvider = " + credentialName1,
|
"AWSCredentialsProvider = " + credentialNameKinesis,
|
||||||
|
"AWSCredentialsProviderDynamoDB = " + credentialNameDynamoDB,
|
||||||
|
"AWSCredentialsProviderCloudWatch = " + credentialNameCloudWatch,
|
||||||
|
"failoverTimeMillis = 100",
|
||||||
|
"shardSyncIntervalMillis = 500"
|
||||||
|
}, '\n');
|
||||||
|
InputStream input = new ByteArrayInputStream(test.getBytes());
|
||||||
|
|
||||||
|
// separate input stream with getConfiguration to explicitly catch exception from the getConfiguration statement
|
||||||
|
KinesisClientLibConfiguration config = configurator.getConfiguration(input);
|
||||||
|
try {
|
||||||
|
config.getKinesisCredentialsProvider().getCredentials();
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail("Kinesis credential providers should not fail.");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
config.getDynamoDBCredentialsProvider().getCredentials();
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail("DynamoDB credential providers should not fail.");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
config.getCloudWatchCredentialsProvider().getCredentials();
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail("CloudWatch credential providers should not fail.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithDifferentAWSCredentialsForDynamoDBAndCloudWatchFailed() {
|
||||||
|
String test = StringUtils.join(new String[] {
|
||||||
|
"streamName = a",
|
||||||
|
"applicationName = b",
|
||||||
|
"AWSCredentialsProvider = " + credentialNameKinesis,
|
||||||
"AWSCredentialsProviderDynamoDB = " + credentialName1,
|
"AWSCredentialsProviderDynamoDB = " + credentialName1,
|
||||||
"AWSCredentialsProviderCloudWatch = " + credentialName1,
|
"AWSCredentialsProviderCloudWatch = " + credentialName1,
|
||||||
"failoverTimeMillis = 100",
|
"failoverTimeMillis = 100",
|
||||||
|
|
@ -343,10 +381,23 @@ public class KinesisClientLibConfiguratorTest {
|
||||||
InputStream input = new ByteArrayInputStream(test.getBytes());
|
InputStream input = new ByteArrayInputStream(test.getBytes());
|
||||||
|
|
||||||
// separate input stream with getConfiguration to explicitly catch exception from the getConfiguration statement
|
// separate input stream with getConfiguration to explicitly catch exception from the getConfiguration statement
|
||||||
|
|
||||||
|
// separate input stream with getConfiguration to explicitly catch exception from the getConfiguration statement
|
||||||
|
KinesisClientLibConfiguration config = configurator.getConfiguration(input);
|
||||||
try {
|
try {
|
||||||
KinesisClientLibConfiguration config = configurator.getConfiguration(input);
|
|
||||||
config.getKinesisCredentialsProvider().getCredentials();
|
config.getKinesisCredentialsProvider().getCredentials();
|
||||||
fail("expect failure with wrong credentials provider");
|
} catch (Exception e) {
|
||||||
|
fail("Kinesis credential providers should not fail.");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
config.getDynamoDBCredentialsProvider().getCredentials();
|
||||||
|
fail("DynamoDB credential providers should fail.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
// succeed
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
config.getCloudWatchCredentialsProvider().getCredentials();
|
||||||
|
fail("CloudWatch credential providers should fail.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// succeed
|
// succeed
|
||||||
}
|
}
|
||||||
|
|
@ -368,6 +419,84 @@ public class KinesisClientLibConfiguratorTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This credentials provider will always succeed
|
||||||
|
*/
|
||||||
|
public static class AlwaysSucceedCredentialsProviderKinesis implements AWSCredentialsProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AWSCredentials getCredentials() {
|
||||||
|
return new AWSCredentials() {
|
||||||
|
@Override
|
||||||
|
public String getAWSAccessKeyId() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAWSSecretKey() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This credentials provider will always succeed
|
||||||
|
*/
|
||||||
|
public static class AlwaysSucceedCredentialsProviderDynamoDB implements AWSCredentialsProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AWSCredentials getCredentials() {
|
||||||
|
return new AWSCredentials() {
|
||||||
|
@Override
|
||||||
|
public String getAWSAccessKeyId() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAWSSecretKey() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This credentials provider will always succeed
|
||||||
|
*/
|
||||||
|
public static class AlwaysSucceedCredentialsProviderCloudWatch implements AWSCredentialsProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AWSCredentials getCredentials() {
|
||||||
|
return new AWSCredentials() {
|
||||||
|
@Override
|
||||||
|
public String getAWSAccessKeyId() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAWSSecretKey() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This credentials provider will always fail
|
* This credentials provider will always fail
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue