use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project incubator-servicecomb-java-chassis by apache.
the class TcpClientConnection method tryLogin.
protected void tryLogin() {
if (!localSupportLogin || !remoteSupportLogin) {
LOGGER.error("local or remote not support login, address={}, localSupportLogin={}, remoteSupportLogin={}.", socketAddress.toString(), localSupportLogin, remoteSupportLogin);
onLoginSuccess();
return;
}
this.status = Status.TRY_LOGIN;
LOGGER.info("try login to address {}", socketAddress.toString());
try (TcpOutputStream os = createLogin()) {
requestMap.put(os.getMsgId(), new TcpRequest(clientConfig.getRequestTimeoutMillis(), this::onLoginResponse));
netSocket.write(os.getBuffer());
}
}
use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayCodec method testEncodeRequest.
@Test
public void testEncodeRequest() {
boolean status = true;
try {
commonMock();
TcpOutputStream os = HighwayCodec.encodeRequest(0, invocation, operationProtobuf, null);
Assert.assertNotNull(os);
Assert.assertArrayEquals(TcpParser.TCP_MAGIC, os.getBuffer().getBytes(0, 7));
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
}
use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project java-chassis by ServiceComb.
the class TestHighwayCodec method testEncodeRequest.
@Test
public void testEncodeRequest() {
boolean status = true;
try {
commonMock();
Map<String, Object> args = new HashMap<>(0);
Mockito.when(invocation.getInvocationArguments()).thenReturn(args);
Mockito.when(requestSerializer.serialize(args)).thenReturn(new byte[0]);
TcpOutputStream os = HighwayCodec.encodeRequest(0, invocation, operationProtobuf);
Assert.assertNotNull(os);
Assert.assertArrayEquals(TcpParser.TCP_MAGIC, os.getBuffer().getBytes(0, 7));
} catch (Exception e) {
e.printStackTrace();
status = false;
}
Assert.assertTrue(status);
}
use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project incubator-servicecomb-java-chassis by apache.
the class TestTcpParser method test.
@Test
public void test() throws UnsupportedEncodingException {
TcpBufferHandler output = new TcpBufferHandler() {
@Override
public void handle(long _msgId, Buffer _headerBuffer, Buffer _bodyBuffer) {
msgId = _msgId;
headerBuffer = _headerBuffer;
bodyBuffer = _bodyBuffer;
}
};
byte[] header = new byte[] { 1, 2, 3 };
byte[] body = new byte[] { 1, 2, 3, 4 };
TcpOutputStream os = new TcpOutputStream(1);
os.writeInt(header.length + body.length);
os.writeInt(header.length);
os.write(header);
os.write(body);
TcpParser parser = new TcpParser(output);
parser.handle(os.getBuffer());
os.close();
Assert.assertEquals(1, msgId);
Assert.assertArrayEquals(header, headerBuffer.getBytes());
Assert.assertArrayEquals(body, bodyBuffer.getBytes());
}
use of org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream in project incubator-servicecomb-java-chassis by apache.
the class TcpClientConnection method writePackageInContext.
private void writePackageInContext() {
for (; ; ) {
AbstractTcpClientPackage pkg = packageQueue.poll();
if (pkg == null) {
break;
}
try (TcpOutputStream os = pkg.createStream()) {
Buffer buf = os.getBuffer();
netSocket.write(buf);
}
}
}
Aggregations