use of org.apache.avro.ipc.NettyServer in project camel by apache.
the class AvroNettyProducerTest method initializeServer.
@Override
protected void initializeServer() {
if (server == null) {
server = new NettyServer(new SpecificResponder(KeyValueProtocol.PROTOCOL, keyValue), new InetSocketAddress("localhost", avroPort));
server.start();
}
if (serverReflection == null) {
serverReflection = new NettyServer(new ReflectResponder(TestReflection.class, testReflection), new InetSocketAddress("localhost", avroPortReflection));
serverReflection.start();
}
}
use of org.apache.avro.ipc.NettyServer in project camel by apache.
the class AvroListener method initAndStartServer.
/**
* Initializes and starts http or netty server on basis of transport protocol from configuration.
*
*
* @param configuration
* @return Initialized and started server
* @throws java.io.IOException
*/
private Server initAndStartServer(AvroConfiguration configuration) throws Exception {
SpecificResponder responder;
Server server;
if (configuration.isReflectionProtocol()) {
responder = new AvroReflectResponder(configuration.getProtocol(), this);
} else {
responder = new AvroSpecificResponder(configuration.getProtocol(), this);
}
if (AVRO_HTTP_TRANSPORT.equalsIgnoreCase(configuration.getTransport().name())) {
server = new HttpServer(responder, configuration.getPort());
} else if (AVRO_NETTY_TRANSPORT.equalsIgnoreCase(configuration.getTransport().name())) {
server = new NettyServer(responder, new InetSocketAddress(configuration.getHost(), configuration.getPort()));
} else {
throw new IllegalArgumentException("Unknown transport " + configuration.getTransport());
}
server.start();
return server;
}
use of org.apache.avro.ipc.NettyServer in project mist by snuspl.
the class MISTDefaultExecutionEnvironmentImplTest method testMISTDefaultExecutionEnvironment.
/**
* This unit test creates mock jar file, mocking driver, and mocking task and tests
* whether a test query can be serialized and sent via MISTDefaultExecutionEnvironmentImpl.
*/
@Test
public void testMISTDefaultExecutionEnvironment() throws IOException {
// Step 1: Launch mock RPC Server
final Server masterServer = new NettyServer(new SpecificResponder(ClientToMasterMessage.class, new MockMasterServer(host, taskPortNum)), new InetSocketAddress(masterPortNum));
final Server taskServer = new NettyServer(new SpecificResponder(ClientToTaskMessage.class, new MockTaskServer(testQueryResult)), new InetSocketAddress(taskPortNum));
// Step 2: Upload jar file
final int suffixStartIndex = mockJarOutName.lastIndexOf(".");
final String mockJarOutPrefix = mockJarOutName.substring(0, suffixStartIndex);
final String mockJarOutSuffix = mockJarOutName.substring(suffixStartIndex);
final List<String> jarPaths = new LinkedList<>();
final Path tempJarFile = Files.createTempFile(mockJarOutPrefix, mockJarOutSuffix);
jarPaths.add(tempJarFile.toString());
final MISTExecutionEnvironment executionEnvironment = new MISTDefaultExecutionEnvironmentImpl(host, masterPortNum);
final JarUploadResult jarUploadResult = executionEnvironment.submitJar(jarPaths);
Assert.assertEquals("app_id", jarUploadResult.getIdentifier());
// Step 3: Generate a new query
final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
queryBuilder.setApplicationId(jarUploadResult.getIdentifier()).socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF).flatMap(s -> Arrays.asList(s.split(" "))).map(s -> new Tuple2<>(s, 1)).reduceByKey(0, String.class, (Integer x, Integer y) -> x + y).textSocketOutput("localhost", 13667);
final MISTQuery query = queryBuilder.build();
System.err.println(mockJarOutPrefix);
System.err.println(mockJarOutSuffix);
// Step 4: Send a query and check whether the query comes to the task correctly
final APIQueryControlResult result = executionEnvironment.submitQuery(query);
Assert.assertEquals(result.getQueryId(), testQueryResult);
masterServer.close();
taskServer.close();
Files.delete(tempJarFile);
}
Aggregations