forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make LocalRunner work properly with .nar files that aren't on the cla…
…sspath (apache#9673) - also support the previous choice of providing the implementation classes on the Thread context classloader classpath - Pass nar file locations as system properties to tests: - Pass pulsar-io cassandra and twitter nar file locations as system properties to tests - Pass pulsar-io-data-generator.nar and pulsar-functions-api-examples.jar file locations as system properties to tests - Improve LocalRunner cleanup/shutdown which wasn't handled before. - Fix invalid test in PackagesApiTest - Make PulsarFunction tests and Sink/Source tests work with .nar files which aren't on the classpath. - Extract FileServer in tests to simplify the test code Co-authored-by: Matteo Merli <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,295 additions
and
1,058 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
pulsar-broker/src/test/java/org/apache/pulsar/functions/worker/FileServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
package org.apache.pulsar.functions.worker; | ||
|
||
import com.google.api.Http; | ||
import com.sun.net.httpserver.Headers; | ||
import com.sun.net.httpserver.HttpServer; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.net.InetSocketAddress; | ||
import java.nio.file.Files; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Simple http server for serving files in Pulsar Function test cases | ||
*/ | ||
@Slf4j | ||
public class FileServer implements AutoCloseable { | ||
private final HttpServer httpServer; | ||
|
||
public FileServer() throws IOException { | ||
httpServer = HttpServer.create(new InetSocketAddress(0), 0); | ||
// creates a default executor | ||
httpServer.setExecutor(null); | ||
} | ||
|
||
public void serveFile(String path, File file) { | ||
httpServer.createContext(path, he -> { | ||
try { | ||
Headers headers = he.getResponseHeaders(); | ||
headers.add("Content-Type", "application/octet-stream"); | ||
|
||
he.sendResponseHeaders(200, file.length()); | ||
try (OutputStream outputStream = he.getResponseBody()) { | ||
Files.copy(file.toPath(), outputStream); | ||
} | ||
} catch (Exception e) { | ||
log.error("Error serving file {} for path {}", file, path, e); | ||
} | ||
}); | ||
} | ||
|
||
public void start() { | ||
httpServer.start(); | ||
} | ||
|
||
public void stop() { | ||
httpServer.stop(0); | ||
} | ||
|
||
public String getUrl(String path) { | ||
return "http://127.0.0.1:" + httpServer.getAddress().getPort() + path; | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.