Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue-86] Pass Pravega credentials as environment variables for integration test #87

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies {
}
testCompile group: 'org.mockito', name: 'mockito-all', version: mockitoVersion
testCompile group: 'org.apache.hadoop', name: 'hadoop-common', version: hadoopVersion
testCompile group: 'com.github.stefanbirkner', name: 'system-rules', version: junitSystemRulesVersion

compileOnly group: 'org.apache.hadoop', name: 'hadoop-common', version: hadoopVersion
compileOnly group: 'org.apache.hadoop', name: 'hadoop-mapreduce-client-core', version: hadoopVersion
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ curatorVersion=4.0.0
gradleGitPluginVersion=1.7.2
hadoopVersion=2.8.1
junitVersion=4.12
junitSystemRulesVersion=1.19.0
mockitoVersion=1.10.19
scalaVersion=2.11.8
shadowGradlePlugin=2.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import io.pravega.connectors.hadoop.utils.SetupUtils;
import org.apache.hadoop.conf.Configuration;
import org.junit.Before;
import org.junit.Rule;
import org.junit.contrib.java.lang.system.EnvironmentVariables;

import java.io.File;
import java.io.IOException;
Expand All @@ -20,13 +23,28 @@

public abstract class ConnectorBaseITCase {

public void addSecurityConfiguration(Configuration conf, SetupUtils setupUtils) throws IOException {
@Rule
public final EnvironmentVariables environmentVariables = new EnvironmentVariables();

protected final SetupUtils setupUtils;

public ConnectorBaseITCase() {
this.setupUtils = new SetupUtils();
}

/**
* Configure security credentials information as environment variables for the Pravega ClientConfig to
* make use of it to initialize the default Credentials instance.
*/
@Before
public void initialize() {
if (setupUtils.isEnableAuth()) {
conf.set("pravega_client_auth_method", "Default");
conf.set("pravega_client_auth_token", SetupUtils.defaultAuthToken());
environmentVariables.set("pravega_client_auth_method", "Basic");
environmentVariables.set("pravega_client_auth_token", SetupUtils.defaultAuthToken());
}
}

public void addSecurityConfiguration(Configuration conf) throws IOException {
if (setupUtils.isEnableTls()) {
File file = new File(setupUtils.getTrustStoreCertFile());
byte[] trustStore = Files.readAllBytes(file.toPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.pravega.client.stream.EventStreamReader;
import io.pravega.client.stream.EventStreamWriter;
import io.pravega.client.stream.impl.JavaSerializer;
import io.pravega.connectors.hadoop.utils.SetupUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -44,7 +43,6 @@ public class PravegaConnectorLocalJobITCase extends ConnectorBaseITCase {
private static final String TEST_STREAM = "stream";
private static final String TEST_STREAM_OUT = "streamout";
private static final int NUM_SEGMENTS = 3;
private static final SetupUtils SETUP_UTILS = new SetupUtils();

private Path outputPath;
private Job job;
Expand All @@ -54,15 +52,15 @@ public class PravegaConnectorLocalJobITCase extends ConnectorBaseITCase {
@Before
public void setUp() throws Exception {
// setup pravega server
SETUP_UTILS.startAllServices(TEST_SCOPE);
SETUP_UTILS.createTestStream(TEST_STREAM, NUM_SEGMENTS);
SETUP_UTILS.createTestStream(TEST_STREAM_OUT, NUM_SEGMENTS);
writer = SETUP_UTILS.getStringWriter(TEST_STREAM);
setupUtils.startAllServices(TEST_SCOPE);
setupUtils.createTestStream(TEST_STREAM, NUM_SEGMENTS);
setupUtils.createTestStream(TEST_STREAM_OUT, NUM_SEGMENTS);
writer = setupUtils.getStringWriter(TEST_STREAM);
}

@After
public void tearDownPravega() throws Exception {
SETUP_UTILS.stopAllServices();
setupUtils.stopAllServices();
if (outputPath != null && fs.exists(outputPath)) {
fs.delete(outputPath, true);
}
Expand Down Expand Up @@ -109,7 +107,7 @@ public void testPravegaConnectorInput() throws Exception {
}

String endPos1 = PravegaInputFormat.fetchLatestPosition(
SETUP_UTILS.getClientConfig(), TEST_SCOPE, TEST_STREAM);
setupUtils.getClientConfig(), TEST_SCOPE, TEST_STREAM);

// won't be read because it's written after end poisitions are fetched
writer.writeEvent("onemore");
Expand Down Expand Up @@ -141,7 +139,7 @@ public void testPravegaConnectorInput() throws Exception {
}

String endPos2 = PravegaInputFormat.fetchLatestPosition(
SETUP_UTILS.getClientConfig(), TEST_SCOPE, TEST_STREAM);
setupUtils.getClientConfig(), TEST_SCOPE, TEST_STREAM);

// won't be read because it's written after end poisitions are fetched
writer.writeEvent("twomore");
Expand Down Expand Up @@ -181,7 +179,7 @@ public void testPravegaConnectorInput() throws Exception {

private Job prepareJobWithInputConfig(Configuration conf, Path outputPath, String startPos, String endPos) throws Exception {
Configuration inputConf = prepareInputFormatConfiguration(conf, startPos, endPos);
addSecurityConfiguration(inputConf, SETUP_UTILS);
addSecurityConfiguration(inputConf);

Job job = Job.getInstance(inputConf, "WordCount");
job.setJarByClass(PravegaConnectorLocalJobITCase.class);
Expand Down Expand Up @@ -234,7 +232,7 @@ public void testPravegaConnectorOutput() throws Exception {
job.waitForCompletion(true);
Assert.assertTrue(job.isSuccessful());

EventStreamReader<String> reader = SETUP_UTILS.getStringReader(TEST_STREAM_OUT);
EventStreamReader<String> reader = setupUtils.getStringReader(TEST_STREAM_OUT);
Set<String> result = new HashSet();
for (int i = 0; i < 4; i++) {
String event = reader.readNextEvent(1000).getEvent();
Expand All @@ -253,7 +251,7 @@ private Job prepareJobWithInputAndOutputConfig(Configuration conf, Path outputPa

Configuration inputConf = prepareInputFormatConfiguration(conf, startPos, endPos);
Configuration outputConf = prepareOutputFormatConfiguration(inputConf);
addSecurityConfiguration(outputConf, SETUP_UTILS);
addSecurityConfiguration(outputConf);

Job job = Job.getInstance(outputConf, "InAndOut");

Expand All @@ -276,7 +274,7 @@ private Configuration prepareInputFormatConfiguration(Configuration conf, String
return PravegaInputFormat.builder(conf)
.withScope(TEST_SCOPE)
.forStream(TEST_STREAM)
.withURI(SETUP_UTILS.getControllerUri().toString())
.withURI(setupUtils.getControllerUri().toString())
.withDeserializer(JavaSerializer.class.getName())
.startPosition(startPos)
.endPosition(endPos)
Expand All @@ -287,7 +285,7 @@ private Configuration prepareOutputFormatConfiguration(Configuration conf) {
return PravegaOutputFormat.builder(conf)
.withScope(TEST_SCOPE)
.forStream(TEST_STREAM_OUT)
.withURI(SETUP_UTILS.getControllerUri().toString())
.withURI(setupUtils.getControllerUri().toString())
.withSerializer(JavaSerializer.class.getName())
.withEventRouter(EventRouter.class.getName())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import io.pravega.client.stream.EventStreamWriter;
import io.pravega.client.stream.impl.JavaSerializer;
import io.pravega.connectors.hadoop.utils.SetupUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
Expand Down Expand Up @@ -44,7 +43,6 @@ public class PravegaConnectorMiniYarnITCase extends ConnectorBaseITCase {
private static final String TEST_STREAM = "stream";
private static final int NUM_SEGMENTS = 3;
private static final int NUM_NODES = 2;
private static final SetupUtils SETUP_UTILS = new SetupUtils();

private Path outputPath;
private Job job;
Expand All @@ -54,17 +52,17 @@ public class PravegaConnectorMiniYarnITCase extends ConnectorBaseITCase {
@Before
public void setUp() throws Exception {
// setup pravega server
SETUP_UTILS.startAllServices(TEST_SCOPE);
SETUP_UTILS.createTestStream(TEST_STREAM, NUM_SEGMENTS);
EventStreamWriter<String> writer = SETUP_UTILS.getStringWriter(TEST_STREAM);
setupUtils.startAllServices(TEST_SCOPE);
setupUtils.createTestStream(TEST_STREAM, NUM_SEGMENTS);
EventStreamWriter<String> writer = setupUtils.getStringWriter(TEST_STREAM);
writer.writeEvent("pravega test");
writer.writeEvent("pravega job test");
writer.writeEvent("pravega local job test");
writer.flush();

// setup mini dfs cluster
YarnConfiguration conf = new YarnConfiguration();
addSecurityConfiguration(conf, SETUP_UTILS);
addSecurityConfiguration(conf);

conf.setBoolean("yarn.is.minicluster", true);
dfsCluster = new MiniDFSCluster.Builder(conf).numDataNodes(NUM_NODES).build();
Expand Down Expand Up @@ -92,7 +90,7 @@ public void tearDownPravega() throws Exception {
if (dfsCluster != null) {
dfsCluster.shutdown();
}
SETUP_UTILS.stopAllServices();
setupUtils.stopAllServices();
}

@Test
Expand All @@ -111,7 +109,7 @@ private Job configureJob(Configuration conf, Path outputPath) throws Exception {
conf = PravegaInputFormat.builder(conf)
.withScope(TEST_SCOPE)
.forStream(TEST_STREAM)
.withURI(SETUP_UTILS.getControllerUri().toString())
.withURI(setupUtils.getControllerUri().toString())
.withDeserializer(JavaSerializer.class.getName())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.pravega.client.stream.impl.ControllerImplConfig;
import io.pravega.client.stream.impl.StreamImpl;
import io.pravega.connectors.hadoop.utils.IntegerSerializer;
import io.pravega.connectors.hadoop.utils.SetupUtils;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -43,29 +42,28 @@ public class PravegaInputFormatITCase extends ConnectorBaseITCase {
private static final String TEST_SCOPE = "PravegaInputFormatITCase";
private static final String TEST_STREAM = "stream";
private static final int USED_SPACE_PER_INTEGER = 12;
private static final SetupUtils SETUP_UTILS = new SetupUtils();

private ScheduledExecutorService executor;
private ControllerImpl controller = null;
private EventStreamWriter<Integer> writer;

@Before
public void setupPravega() throws Exception {
SETUP_UTILS.startAllServices(TEST_SCOPE);
SETUP_UTILS.createTestStream(TEST_STREAM, 1);
writer = SETUP_UTILS.getIntegerWriter(TEST_STREAM);
setupUtils.startAllServices(TEST_SCOPE);
setupUtils.createTestStream(TEST_STREAM, 1);
writer = setupUtils.getIntegerWriter(TEST_STREAM);

executor = Executors.newSingleThreadScheduledExecutor();
controller = new ControllerImpl(ControllerImplConfig.builder()
.clientConfig(SETUP_UTILS.getClientConfig())
.clientConfig(setupUtils.getClientConfig())
.retryAttempts(1).build(),
executor);
}

@After
public void tearDownPravega() throws Exception {
executor.shutdown();
SETUP_UTILS.stopAllServices();
setupUtils.stopAllServices();
}

@Test
Expand All @@ -74,11 +72,11 @@ public void testGetSplits() throws IOException, ExecutionException, InterruptedE
conf = PravegaInputFormat.builder(conf)
.withScope(TEST_SCOPE)
.forStream(TEST_STREAM)
.withURI(SETUP_UTILS.getControllerUri().toString())
.withURI(setupUtils.getControllerUri().toString())
.withDeserializer(IntegerSerializer.class.getName())
.build();

addSecurityConfiguration(conf, SETUP_UTILS);
addSecurityConfiguration(conf);
Job job = new Job(conf);

writeEvents(20, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import io.pravega.client.stream.EventStreamWriter;
import io.pravega.connectors.hadoop.utils.IntegerSerializer;
import io.pravega.connectors.hadoop.utils.SetupUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.InputFormat;
import org.apache.hadoop.mapreduce.InputSplit;
Expand All @@ -38,32 +37,27 @@ public class PravegaInputRecordReaderITCase extends ConnectorBaseITCase {
private static final String TEST_STREAM_2 = "stream2";
private static final int NUM_EVENTS = 20;

/**
* Setup utility
*/
private static final SetupUtils SETUP_UTILS = new SetupUtils();

@Before
public void setupPravega() throws Exception {
SETUP_UTILS.startAllServices(TEST_SCOPE);
setupUtils.startAllServices(TEST_SCOPE);
}

@After
public void tearDownPravega() throws Exception {
SETUP_UTILS.stopAllServices();
setupUtils.stopAllServices();
}

@Test
public void testReadFromSingleSegment() throws Exception {
SETUP_UTILS.createTestStream(TEST_STREAM_1, 1);
EventStreamWriter<Integer> writer = SETUP_UTILS.getIntegerWriter(TEST_STREAM_1);
setupUtils.createTestStream(TEST_STREAM_1, 1);
EventStreamWriter<Integer> writer = setupUtils.getIntegerWriter(TEST_STREAM_1);
for (int i = 0; i < NUM_EVENTS; i++) {
CompletableFuture future = writer.writeEvent(i);
future.get();
}

Configuration conf = getConfiguration(TEST_STREAM_1);
addSecurityConfiguration(conf, SETUP_UTILS);
addSecurityConfiguration(conf);
Job job = new Job(conf);

// get an InputSplit
Expand All @@ -87,15 +81,15 @@ public void testReadFromSingleSegment() throws Exception {

@Test
public void testReadFromMultiSegments() throws Exception {
SETUP_UTILS.createTestStream(TEST_STREAM_2, 2);
EventStreamWriter<Integer> writer = SETUP_UTILS.getIntegerWriter(TEST_STREAM_2);
setupUtils.createTestStream(TEST_STREAM_2, 2);
EventStreamWriter<Integer> writer = setupUtils.getIntegerWriter(TEST_STREAM_2);
for (int i = 0; i < NUM_EVENTS; i++) {
CompletableFuture future = writer.writeEvent(i);
future.get();
}

Configuration conf = getConfiguration(TEST_STREAM_2);
addSecurityConfiguration(conf, SETUP_UTILS);
addSecurityConfiguration(conf);
Job job = new Job(conf);

// get an InputSplit
Expand All @@ -120,7 +114,7 @@ private Configuration getConfiguration(final String stream) {
return PravegaInputFormat.builder()
.withScope(TEST_SCOPE)
.forStream(stream)
.withURI(SETUP_UTILS.getControllerUri().toString())
.withURI(setupUtils.getControllerUri().toString())
.withDeserializer(IntegerSerializer.class.getName())
.build();
}
Expand Down