use of edu.snu.mist.core.sinks.Sink in project mist by snuspl.
the class PhysicalObjectGeneratorTest method testSuccessOfSink.
@Test
public void testSuccessOfSink() throws IOException, InjectionException {
final int port = 13667;
final ServerSocket socket = new ServerSocket(port);
final Map<String, String> conf = new HashMap<String, String>() {
{
put(ConfKeys.SinkConf.SINK_TYPE.name(), ConfValues.SinkType.NETTY.name());
put(ConfKeys.NettySink.SINK_ADDRESS.name(), "localhost");
put(ConfKeys.NettySink.SINK_PORT.name(), String.valueOf(port));
}
};
final Sink sink = generator.newSink(conf, classLoader);
Assert.assertTrue(sink instanceof NettyTextSink);
socket.close();
}
use of edu.snu.mist.core.sinks.Sink in project mist by snuspl.
the class PhysicalObjectGenerator method newSink.
/**
* Get a new sink.
* @param conf configuration
* @param classLoader external class loader
* @return new sink
*/
@SuppressWarnings("unchecked")
public <T> Sink<T> newSink(final Map<String, String> conf, final ClassLoader classLoader) throws IOException {
final String type = conf.get(ConfKeys.SinkConf.SINK_TYPE.name());
if (type.equals(ConfValues.SinkType.NETTY.name())) {
final String serverAddress = conf.get(ConfKeys.NettySink.SINK_ADDRESS.name());
final int serverPort = Integer.valueOf(conf.get(ConfKeys.NettySink.SINK_PORT.name()));
return (Sink<T>) new NettyTextSink(serverAddress, serverPort, nettySharedResource, identifierFactory);
} else if (type.equals(ConfValues.SinkType.MQTT.name())) {
final String brokerURI = conf.get(ConfKeys.MqttSink.MQTT_SINK_BROKER_URI.name());
final String topic = conf.get(ConfKeys.MqttSink.MQTT_SINK_TOPIC.name());
try {
return (Sink<T>) new MqttSink(brokerURI, topic, mqttSharedResource);
} catch (final MqttException e) {
e.printStackTrace();
throw new IOException(e);
}
} else {
throw new RuntimeException("Invalid sink type: " + type);
}
}
use of edu.snu.mist.core.sinks.Sink in project mist by snuspl.
the class PhysicalObjectGeneratorTest method testSuccessOfMqttSink.
/**
* Test if the mqtt sink is created successfully.
*/
@Test
public void testSuccessOfMqttSink() throws IOException, InjectionException {
final Server mqttBroker = MqttUtils.createMqttBroker();
final String topic = "mqttTest";
final Map<String, String> conf = new HashMap<String, String>() {
{
put(ConfKeys.SinkConf.SINK_TYPE.name(), ConfValues.SinkType.MQTT.name());
put(ConfKeys.MqttSink.MQTT_SINK_BROKER_URI.name(), MqttUtils.BROKER_URI);
put(ConfKeys.MqttSink.MQTT_SINK_TOPIC.name(), topic);
}
};
final Sink sink = generator.newSink(conf, classLoader);
Assert.assertTrue(sink instanceof MqttSink);
mqttBroker.stopServer();
}
Aggregations