use of com.nokia.dempsy.messagetransport.Destination in project Dempsy by Dempsy.
the class PassthroughTransport method createOutbound.
@Override
public SenderFactory createOutbound(DempsyExecutor executor, final StatsCollector statsCollector) {
return new SenderFactory() {
private volatile boolean isStopped = false;
private StatsCollector sc = statsCollector;
@Override
public Sender getSender(Destination destination) throws MessageTransportException {
if (isStopped == true)
throw new MessageTransportException("getSender called for the destination " + SafeString.valueOf(destination) + " on a stopped " + SafeString.valueOfClass(this));
PassthroughSender ret = (PassthroughSender) (((PassthroughDestination) destination).sender);
ret.statsCollector = sc;
return ret;
}
@Override
public void stop() {
isStopped = true;
}
// There is no 'stop' on a PassthroughSender so there's nothing to do to reclaim it.
@Override
public void reclaim(Destination destination) {
}
};
}
use of com.nokia.dempsy.messagetransport.Destination in project Dempsy by Dempsy.
the class TestStatsCollectorCoda method testEnvPrefixFromSystemProperty.
@Test
public void testEnvPrefixFromSystemProperty() throws Throwable {
tearDown();
System.setProperty(StatsCollectorFactoryCoda.environmentPrefixSystemPropertyName, "Hello.");
setUp();
StatsCollectorFactoryCoda.MetricNamingStrategy strategy = statsCollectorFactory.getNamingStrategy();
ClusterId clusterId = new ClusterId("app", "cluster");
MetricName name = strategy.createName(clusterId, "metric");
assertEquals("metric", name.getName());
assertEquals("app-cluster", name.getGroup());
assertTrue(strategy.buildPrefix(clusterId, new Destination() {
@Override
public String toString() {
return "destination";
}
}).startsWith("Hello."));
// make sure setting the environment prefix doesn't effect the -D option
statsCollectorFactory.setEnvironmentPrefix("otherEnvPrefix");
assertTrue(strategy.buildPrefix(clusterId, new Destination() {
@Override
public String toString() {
return "destination";
}
}).startsWith("Hello."));
// make sure that without the system property the setEnvironmentPrefix value works
System.getProperties().remove(StatsCollectorFactoryCoda.environmentPrefixSystemPropertyName);
assertTrue(strategy.buildPrefix(clusterId, new Destination() {
@Override
public String toString() {
return "destination";
}
}).startsWith("otherEnvPrefix"));
// make sure that delting the environmentPrefix doesn't create an issue.
statsCollectorFactory.setEnvironmentPrefix(null);
strategy.buildPrefix(clusterId, new Destination() {
@Override
public String toString() {
return "destination";
}
}).startsWith("otherEnvPrefix");
}
use of com.nokia.dempsy.messagetransport.Destination in project Dempsy by Dempsy.
the class BlockingQueueTest method testBlockingQueueUsingDestination.
@Test
public void testBlockingQueueUsingDestination() throws Exception {
try {
setUp2("/blockingqueueTest2AppContext.xml");
Destination destination = destinationFactory.getDestination();
Sender lsender = senderFactory.getSender(destination);
lsender.send("Hello".getBytes());
String message = new String(pojo.getMessage());
assertEquals("Hello", message);
assertEquals(0, overflowHandler.overflowCalled);
} finally {
if (ctx != null)
tearDown();
}
}
use of com.nokia.dempsy.messagetransport.Destination in project Dempsy by Dempsy.
the class TcpTransportTest method transportLargeMessage.
/**
* Test the sending and recieving of a large message (10 meg).
* @throws Throwable
*/
@Test
public void transportLargeMessage() throws Throwable {
int port = -1;
boolean localhost = false;
SenderFactory factory = null;
TcpReceiver adaptor = null;
TcpSenderFactory senderFactory = null;
try {
//===========================================
// setup the sender and receiver
adaptor = new TcpReceiver(null, getFailFast());
// distruptible sender factory
factory = makeSenderFactory(false, null, 500);
receiveLargeMessageLatch = new CountDownLatch(1);
adaptor.setListener(new Listener() {
@Override
public boolean onMessage(byte[] messageBytes, boolean failfast) throws MessageTransportException {
receivedByteArrayMessage = messageBytes;
receiveLargeMessageLatch.countDown();
return true;
}
@Override
public void shuttingDown() {
}
});
if (port <= 0)
adaptor.setUseEphemeralPort(true);
if (port > 0)
adaptor.setPort(port);
if (localhost)
adaptor.setUseLocalhost(localhost);
//===========================================
// start the adaptor
adaptor.start();
// double start ... just want more coverage.
adaptor.start();
// get the destination
Destination destination = adaptor.getDestination();
if (port > 0)
adaptor.setPort(port);
if (localhost)
adaptor.setUseLocalhost(localhost);
senderFactory = makeSenderFactory(false, null, 500);
int size = 1024 * 1024 * 10;
byte[] tosend = new byte[size];
for (int i = 0; i < size; i++) tosend[i] = (byte) i;
TcpSender sender = (TcpSender) senderFactory.getSender(destination);
// extend the timeout because of the larger messages
sender.setTimeoutMillis(100000);
sender.send(tosend);
assertTrue(receiveLargeMessageLatch.await(1, TimeUnit.MINUTES));
assertArrayEquals(tosend, receivedByteArrayMessage);
} finally {
if (factory != null)
factory.stop();
if (senderFactory != null)
senderFactory.stop();
if (adaptor != null)
adaptor.stop();
receivedByteArrayMessage = null;
}
}
use of com.nokia.dempsy.messagetransport.Destination in project Dempsy by Dempsy.
the class TcpTransportTest method testTransportInstantiation.
/**
* Just send a simple message and make sure it gets through.
*/
@Test
public void testTransportInstantiation() throws Throwable {
final AtomicBoolean batchedAtLeastOnce = new AtomicBoolean(false);
runAllCombinations(new Checker() {
@Override
public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable {
final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination() {
});
SenderFactory factory = null;
TcpReceiver adaptor = null;
try {
boolean shouldBatch = batchOutgoingMessagesDelayMillis >= 0;
if (shouldBatch)
batchedAtLeastOnce.set(true);
TcpTransport transport = new TcpTransport();
transport.setFailFast(getFailFast());
// by default batching isn't disabled.
assertFalse(transport.isBatchingDisabled());
if (!shouldBatch)
transport.setDisableBatching(true);
if (!shouldBatch)
assertTrue(transport.isBatchingDisabled());
assertEquals(!shouldBatch, transport.isBatchingDisabled());
//===========================================
// setup the sender and receiver
adaptor = (TcpReceiver) transport.createInbound(null);
adaptor.setStatsCollector(statsCollector);
StringListener receiver = new StringListener();
adaptor.setListener(receiver);
factory = transport.createOutbound(null, statsCollector);
if (port > 0)
adaptor.setPort(port);
if (localhost)
adaptor.setUseLocalhost(localhost);
//===========================================
// start the adaptor
adaptor.start();
// get the destination
Destination destination = adaptor.getDestination();
// send a message
byte[] messageBytes = "Hello".getBytes();
Sender sender = factory.getSender(destination);
assertEquals((shouldBatch ? TcpTransport.defaultBatchingDelayMillis : -1), ((TcpSender) sender).getBatchOutgoingMessagesDelayMillis());
sender.send(messageBytes);
sender.send(messageBytes);
// wait for it to be received.
for (long endTime = System.currentTimeMillis() + baseTimeoutMillis; endTime > System.currentTimeMillis() && receiver.numMessages.get() < 2; ) Thread.sleep(1);
assertEquals(2, receiver.numMessages.get());
// verify everything came over ok.
assertEquals(1, receiver.receivedStringMessages.size());
assertEquals("Hello", receiver.receivedStringMessages.iterator().next());
if (shouldBatch) {
// verify the histogram
Histogram histogram = ((TcpSender) sender).getBatchingHistogram();
assertEquals(calcMean(2), histogram.mean(), 0.0000001);
assertEquals(1, histogram.count());
}
} finally {
if (factory != null)
factory.stop();
if (adaptor != null)
adaptor.stop();
}
}
@Override
public String toString() {
return "testTransportInstantiation";
}
});
assertTrue(batchedAtLeastOnce.get());
}
Aggregations