2016-07-20 19:46:26 +00:00
|
|
|
/*
|
2018-08-02 17:57:11 +00:00
|
|
|
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2016-07-20 19:46:26 +00:00
|
|
|
*
|
|
|
|
|
* Licensed under the Amazon Software License (the "License").
|
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
|
* A copy of the License is located at
|
|
|
|
|
*
|
|
|
|
|
* http://aws.amazon.com/asl/
|
|
|
|
|
*
|
|
|
|
|
* or in the "license" file accompanying this file. This file is distributed
|
|
|
|
|
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
|
|
|
* express or implied. See the License for the specific language governing
|
|
|
|
|
* permissions and limitations under the License.
|
|
|
|
|
*/
|
2019-01-15 01:35:35 +00:00
|
|
|
package software.amazon.kinesis.multilang;
|
2016-07-20 19:46:26 +00:00
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
2018-08-02 17:57:11 +00:00
|
|
|
import static org.mockito.Matchers.any;
|
|
|
|
|
import static org.mockito.Mockito.when;
|
2016-07-20 19:46:26 +00:00
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
2019-01-15 01:35:35 +00:00
|
|
|
import org.apache.commons.beanutils.BeanUtilsBean;
|
|
|
|
|
import org.apache.commons.beanutils.ConvertUtilsBean;
|
2018-08-02 17:57:11 +00:00
|
|
|
import org.junit.Before;
|
2016-07-20 19:46:26 +00:00
|
|
|
import org.junit.Test;
|
2018-08-02 17:57:11 +00:00
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.mockito.Mock;
|
2016-07-20 19:46:26 +00:00
|
|
|
import org.mockito.Mockito;
|
2018-08-02 17:57:11 +00:00
|
|
|
import org.mockito.runners.MockitoJUnitRunner;
|
2016-07-20 19:46:26 +00:00
|
|
|
|
2018-08-02 17:57:11 +00:00
|
|
|
import junit.framework.Assert;
|
|
|
|
|
import software.amazon.awssdk.auth.credentials.AwsCredentials;
|
|
|
|
|
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
|
2019-01-15 01:35:35 +00:00
|
|
|
import software.amazon.kinesis.multilang.config.KinesisClientLibConfigurator;
|
|
|
|
|
import software.amazon.kinesis.multilang.config.MultiLangDaemonConfiguration;
|
2016-07-20 19:46:26 +00:00
|
|
|
|
2018-08-02 17:57:11 +00:00
|
|
|
@RunWith(MockitoJUnitRunner.class)
|
|
|
|
|
public class MultiLangDaemonConfigTest {
|
2016-07-20 19:46:26 +00:00
|
|
|
private static String FILENAME = "some.properties";
|
|
|
|
|
|
2018-08-02 17:57:11 +00:00
|
|
|
@Mock
|
|
|
|
|
private AwsCredentialsProvider credentialsProvider;
|
|
|
|
|
@Mock
|
|
|
|
|
private AwsCredentials creds;
|
|
|
|
|
@Mock
|
|
|
|
|
private KinesisClientLibConfigurator configurator;
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void setup() {
|
2019-01-15 01:35:35 +00:00
|
|
|
ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean();
|
|
|
|
|
BeanUtilsBean utilsBean = new BeanUtilsBean(convertUtilsBean);
|
|
|
|
|
MultiLangDaemonConfiguration multiLangDaemonConfiguration = new MultiLangDaemonConfiguration(utilsBean,
|
|
|
|
|
convertUtilsBean);
|
|
|
|
|
multiLangDaemonConfiguration.setApplicationName("cool-app");
|
|
|
|
|
multiLangDaemonConfiguration.setStreamName("cool-stream");
|
|
|
|
|
multiLangDaemonConfiguration.setWorkerIdentifier("cool-worker");
|
2018-08-02 17:57:11 +00:00
|
|
|
when(credentialsProvider.resolveCredentials()).thenReturn(creds);
|
|
|
|
|
when(creds.accessKeyId()).thenReturn("cool-user");
|
2019-01-15 01:35:35 +00:00
|
|
|
when(configurator.getConfiguration(any(Properties.class))).thenReturn(multiLangDaemonConfiguration);
|
2016-07-20 19:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void constructorTest() throws IOException {
|
2018-08-02 17:57:11 +00:00
|
|
|
String PROPERTIES = "executableName = randomEXE \n" + "applicationName = testApp \n"
|
|
|
|
|
+ "streamName = fakeStream \n" + "AWSCredentialsProvider = DefaultAWSCredentialsProviderChain\n"
|
|
|
|
|
+ "processingLanguage = malbolge";
|
2016-07-20 19:46:26 +00:00
|
|
|
ClassLoader classLoader = Mockito.mock(ClassLoader.class);
|
|
|
|
|
|
2018-08-02 17:57:11 +00:00
|
|
|
Mockito.doReturn(new ByteArrayInputStream(PROPERTIES.getBytes())).when(classLoader)
|
2016-07-20 19:46:26 +00:00
|
|
|
.getResourceAsStream(FILENAME);
|
|
|
|
|
|
2018-08-02 17:57:11 +00:00
|
|
|
MultiLangDaemonConfig deamonConfig = new MultiLangDaemonConfig(FILENAME, classLoader, configurator);
|
2016-07-20 19:46:26 +00:00
|
|
|
|
|
|
|
|
assertNotNull(deamonConfig.getExecutorService());
|
2019-01-15 01:35:35 +00:00
|
|
|
assertNotNull(deamonConfig.getMultiLangDaemonConfiguration());
|
2016-07-20 19:46:26 +00:00
|
|
|
assertNotNull(deamonConfig.getRecordProcessorFactory());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void propertyValidation() {
|
2018-08-02 17:57:11 +00:00
|
|
|
String PROPERTIES_NO_EXECUTABLE_NAME = "applicationName = testApp \n" + "streamName = fakeStream \n"
|
|
|
|
|
+ "AWSCredentialsProvider = DefaultAWSCredentialsProviderChain\n" + "processingLanguage = malbolge";
|
2016-07-20 19:46:26 +00:00
|
|
|
ClassLoader classLoader = Mockito.mock(ClassLoader.class);
|
|
|
|
|
|
2018-08-02 17:57:11 +00:00
|
|
|
Mockito.doReturn(new ByteArrayInputStream(PROPERTIES_NO_EXECUTABLE_NAME.getBytes())).when(classLoader)
|
2016-07-20 19:46:26 +00:00
|
|
|
.getResourceAsStream(FILENAME);
|
|
|
|
|
|
|
|
|
|
MultiLangDaemonConfig config;
|
|
|
|
|
try {
|
2018-08-02 17:57:11 +00:00
|
|
|
config = new MultiLangDaemonConfig(FILENAME, classLoader, configurator);
|
2016-07-20 19:46:26 +00:00
|
|
|
Assert.fail("Construction of the config should have failed due to property validation failing.");
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
// Good
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Assert.fail();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|