Search in sources :

Example 1 with MockFeedHandler

use of io.cdap.plugin.spark.mock.MockFeedHandler in project hydrator-plugins by cdapio.

the class SparkPluginTest method setupTest.

@BeforeClass
public static void setupTest() throws Exception {
    // add the artifact for data pipeline app
    setupBatchArtifacts(DATAPIPELINE_ARTIFACT_ID, DataPipelineApp.class);
    setupStreamingArtifacts(DATASTREAMS_ARTIFACT_ID, DataStreamsApp.class);
    // add artifact for spark plugins
    Set<ArtifactRange> parents = ImmutableSet.of(new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), DATAPIPELINE_ARTIFACT_ID.getArtifact(), new ArtifactVersion(DATAPIPELINE_ARTIFACT_ID.getVersion()), true, new ArtifactVersion(DATAPIPELINE_ARTIFACT_ID.getVersion()), true), new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), DATASTREAMS_ARTIFACT_ID.getArtifact(), new ArtifactVersion(DATASTREAMS_ARTIFACT_ID.getVersion()), true, new ArtifactVersion(DATASTREAMS_ARTIFACT_ID.getVersion()), true));
    addPluginArtifact(NamespaceId.DEFAULT.artifact("spark-plugins", "1.0.0"), parents, TwitterStreamingSource.class, FileStreamingSource.class, HTTPPollerSource.class, HTTPPollConfig.class);
    List<HttpHandler> handlers = new ArrayList<>();
    handlers.add(new MockFeedHandler());
    httpService = NettyHttpService.builder("MockService").setHttpHandlers(handlers).build();
    httpService.start();
    int port = httpService.getBindAddress().getPort();
    httpBase = "http://localhost:" + port;
    // tell service what its port is.
    URL setPortURL = new URL(httpBase + "/port");
    HttpURLConnection urlConn = (HttpURLConnection) setPortURL.openConnection();
    urlConn.setDoOutput(true);
    urlConn.setRequestMethod(HttpMethod.PUT);
    urlConn.getOutputStream().write(String.valueOf(port).getBytes(Charsets.UTF_8));
    Assert.assertEquals(200, urlConn.getResponseCode());
    urlConn.disconnect();
}
Also used : HttpHandler(io.cdap.http.HttpHandler) MockFeedHandler(io.cdap.plugin.spark.mock.MockFeedHandler) ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) HttpURLConnection(java.net.HttpURLConnection) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) ArrayList(java.util.ArrayList) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Aggregations

ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)1 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)1 HttpHandler (io.cdap.http.HttpHandler)1 MockFeedHandler (io.cdap.plugin.spark.mock.MockFeedHandler)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1