use of com.yahoo.fs4.PingPacket in project vespa by vespa-engine.
the class FastSearcher method ping.
public static Pong ping(Ping ping, Backend backend, String name) {
FS4Channel channel = backend.openPingChannel();
// com.yahoo.prelude.cluster.TrafficNodeMonitor.failed(ErrorMessage)
try {
PingPacket pingPacket = new PingPacket();
try {
boolean couldSend = channel.sendPacket(pingPacket);
if (!couldSend) {
return new Pong(ErrorMessage.createBackendCommunicationError("Could not ping " + name));
}
} catch (InvalidChannelException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("Invalid channel " + name));
} catch (IllegalStateException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("Illegal state in FS4: " + e.getMessage()));
} catch (IOException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("IO error while sending ping: " + e.getMessage()));
}
// We should only get a single packet
BasicPacket[] packets;
try {
packets = channel.receivePackets(ping.getTimeout(), 1);
} catch (ChannelTimeoutException e) {
return new Pong(ErrorMessage.createNoAnswerWhenPingingNode("timeout while waiting for fdispatch for " + name));
} catch (InvalidChannelException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("Invalid channel for " + name));
}
if (packets.length == 0) {
return new Pong(ErrorMessage.createBackendCommunicationError(name + " got no packets back"));
}
try {
ensureInstanceOf(PongPacket.class, packets[0], name);
} catch (TimeoutException e) {
return new Pong(ErrorMessage.createTimeout(e.getMessage()));
} catch (IOException e) {
return new Pong(ErrorMessage.createBackendCommunicationError("Unexpected packet class returned after ping: " + e.getMessage()));
}
return new Pong((PongPacket) packets[0]);
} finally {
if (channel != null) {
channel.close();
}
}
}
use of com.yahoo.fs4.PingPacket in project vespa by vespa-engine.
the class BackendTestCase method requireStatistics.
@Test
public void requireStatistics() throws IOException, InvalidChannelException {
FS4Channel channel = backend.openPingChannel();
server.dispatch.channelId = -1;
server.dispatch.packetData = PONG;
assertTrue(channel.sendPacket(new PingPacket()));
try {
channel.receivePackets(1000, 1);
} catch (ChannelTimeoutException e) {
fail("Could not get packets from simulated backend.");
}
BackendStatistics stats = backend.getStatistics();
assertEquals(1, stats.totalConnections());
}
use of com.yahoo.fs4.PingPacket in project vespa by vespa-engine.
the class MockFSChannel method receivePackets.
public BasicPacket[] receivePackets(long timeout, int packetCount) {
List<BasicPacket> packets = new java.util.ArrayList<>();
if (lastReceived instanceof QueryPacket) {
lastQueryPacket = (QueryPacket) lastReceived;
QueryResultPacket result = QueryResultPacket.create();
result.setDocstamp(docstamp);
result.setChannel(0);
result.setTotalDocumentCount(2);
result.setOffset(lastQueryPacket.getOffset());
if (lastQueryPacket.getOffset() == 0 && lastQueryPacket.getLastOffset() >= 1) {
result.addDocument(new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(123), 2003, 234, 1000));
}
if (lastQueryPacket.getOffset() <= 1 && lastQueryPacket.getLastOffset() >= 2) {
result.addDocument(new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(456), 1855, 234, 1001));
}
packets.add(result);
} else if (lastReceived instanceof GetDocSumsPacket) {
addDocsums(packets, lastQueryPacket);
} else if (lastReceived instanceof PingPacket) {
packets.add(new PongPacket(activeDocuments));
}
while (packetCount >= 0 && packets.size() > packetCount) {
packets.remove(packets.size() - 1);
}
return packets.toArray(new BasicPacket[packets.size()]);
}
Aggregations