Search in sources :

Example 6 with TcpOutputStream

use of io.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();
        TcpOutputStream os = HighwayCodec.encodeRequest(invocation, operationProtobuf);
        Assert.assertNotNull(os);
        Assert.assertArrayEquals(TcpParser.TCP_MAGIC, os.getBuffer().getBytes(0, 7));
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : TcpOutputStream(io.servicecomb.foundation.vertx.tcp.TcpOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with TcpOutputStream

use of io.servicecomb.foundation.vertx.tcp.TcpOutputStream in project java-chassis by ServiceComb.

the class TcpClient method tryLogin.

protected synchronized void tryLogin() {
    if (!remoteSupportLogin) {
        LOGGER.error("remote not support login, address={}.", socketAddress.toString());
        onLoginSuccess();
        return;
    }
    if (clientConfig.getTcpLogin() == null) {
        LOGGER.error("local not support login, address={}.", socketAddress.toString());
        onLoginSuccess();
        return;
    }
    this.status = Status.TRY_LOGIN;
    LOGGER.info("try login to address {}", socketAddress.toString());
    try (TcpOutputStream os = clientConfig.getTcpLogin().createLogin()) {
        requestMap.put(os.getMsgId(), new TcpRequest(clientConfig.getRequestTimeoutMillis(), this::onLoginResponse));
        netSocket.write(os.getBuffer());
    }
}
Also used : TcpOutputStream(io.servicecomb.foundation.vertx.tcp.TcpOutputStream)

Example 8 with TcpOutputStream

use of io.servicecomb.foundation.vertx.tcp.TcpOutputStream in project java-chassis by ServiceComb.

the class TestTcp method testTcpOutputStream.

@Test
public void testTcpOutputStream() {
    TcpOutputStream oStream = new TcpOutputStream();
    oStream.close();
    Buffer buffer = oStream.getBuffer();
    Assert.assertArrayEquals(TcpParser.TCP_MAGIC, buffer.getBytes(0, TcpParser.TCP_MAGIC.length));
    Assert.assertEquals(oStream.getMsgId(), buffer.getLong(TcpParser.TCP_MAGIC.length));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) TcpOutputStream(io.servicecomb.foundation.vertx.tcp.TcpOutputStream) Test(org.junit.Test)

Aggregations

TcpOutputStream (io.servicecomb.foundation.vertx.tcp.TcpOutputStream)8 Test (org.junit.Test)6 Buffer (io.vertx.core.buffer.Buffer)4 TcpClientPool (io.servicecomb.foundation.vertx.client.tcp.TcpClientPool)2 ByteBuf (io.netty.buffer.ByteBuf)1 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)1 AsyncResponse (io.servicecomb.core.AsyncResponse)1 Endpoint (io.servicecomb.core.Endpoint)1 Response (io.servicecomb.core.Response)1 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 TcpClient (io.servicecomb.foundation.vertx.client.tcp.TcpClient)1 TcpClientConfig (io.servicecomb.foundation.vertx.client.tcp.TcpClientConfig)1 TcpClientVerticle (io.servicecomb.foundation.vertx.client.tcp.TcpClientVerticle)1 TcpRequest (io.servicecomb.foundation.vertx.client.tcp.TcpRequest)1 TcpResonseCallback (io.servicecomb.foundation.vertx.client.tcp.TcpResonseCallback)1 LoginRequest (io.servicecomb.transport.highway.message.LoginRequest)1 RequestHeader (io.servicecomb.transport.highway.message.RequestHeader)1 Context (io.vertx.core.Context)1 Handler (io.vertx.core.Handler)1 NetClient (io.vertx.core.net.NetClient)1