List of usage examples for org.apache.thrift TApplicationException BAD_SEQUENCE_ID
int BAD_SEQUENCE_ID
To view the source code for org.apache.thrift TApplicationException BAD_SEQUENCE_ID.
Click Source Link
From source file:com.flipkart.phantom.thrift.impl.ProxyServiceClient.java
License:Apache License
/** * Overriden super class method. Receives the service response and relays it back to the client * @see org.apache.thrift.TServiceClient#receiveBase(org.apache.thrift.TBase, String) *///from w ww . j a v a2 s .co m public void receiveBase(TBase result, String methodName) throws TException { // Read the service response - same as in TServiceClient#receiveBase TMessage msg = iprot_.readMessageBegin(); if (msg.type == TMessageType.EXCEPTION) { TApplicationException x = TApplicationException.read(iprot_); iprot_.readMessageEnd(); throw x; } if (msg.seqid != this.seqid_) { throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, methodName + " failed: out of sequence response"); } result.read(iprot_); iprot_.readMessageEnd(); // now relay the response to the client clientProtocol.writeMessageBegin(msg); result.write(clientProtocol); clientProtocol.writeMessageEnd(); clientProtocol.getTransport().flush(); LOGGER.debug("Relayed thrift response to client. Seq Id : " + msg.seqid + ", Method : " + msg.name + ", value : " + result); }
From source file:com.linecorp.armeria.client.thrift.THttpClientBadSeqIdTest.java
License:Apache License
@Test(timeout = 30000L) public void badSeqId() throws Exception { try (ServerSocket ss = new ServerSocket(0)) { ss.setSoTimeout(5000);// ww w. jav a 2 s . c om final THttpClient client = Clients.newClient("ttext+h1c://127.0.0.1:" + ss.getLocalPort(), THttpClient.class); final RpcResponse res = client.execute("/", HelloService.Iface.class, "hello", "trustin"); assertThat(res.isDone()).isFalse(); try (Socket s = ss.accept()) { final InputStream sin = s.getInputStream(); final OutputStream sout = s.getOutputStream(); // Ensure the request is received before sending its response. assertThat(sin.read()).isGreaterThanOrEqualTo(0); // Send the TTEXT over HTTP/1 response with mismatching seqid. final byte[] thriftTextResponse = ('{' + " \"method\": \"hello\"," + " \"type\": \"CALL\"," + " \"seqid\": " + Integer.MIN_VALUE + ',' + " \"args\": { \"success\": \"Hello, trustin!\" }" + '}') .getBytes(StandardCharsets.US_ASCII); sout.write(("HTTP/1.1 200 OK\r\n" + "Connection: close\r\n" + "Content-Length: " + thriftTextResponse.length + "\r\n" + "\r\n").getBytes(StandardCharsets.US_ASCII)); sout.write(thriftTextResponse); // Wait until the client closes the connection thanks to 'connection: close'. while (sin.read() >= 0) { continue; } } catch (SocketTimeoutException expected) { // A connection was not accepted; Wait for the response to raise the cause. res.join(); // Should not reach here because .join() will fail, but for completeness: throw expected; } assertThatThrownBy(res::get).isInstanceOf(ExecutionException.class) .hasCauseInstanceOf(TApplicationException.class) .satisfies(cause -> assertThat(((TApplicationException) Exceptions.peel(cause)).getType()) .isEqualTo(TApplicationException.BAD_SEQUENCE_ID)); } }
From source file:com.linecorp.armeria.common.thrift.text.TTextProtocolTest.java
License:Apache License
@Test public void rpcTApplicationException() throws Exception { String request = "{\n" + " \"method\" : \"doDebug\",\n" + " \"type\" : \"EXCEPTION\",\n" + " \"seqid\" : 101,\n" + " \"args\" : {\n" + " \"type\" : 4,\n" + " \"message\" : \"bad_seq_id\"\n" + " }\n" + " }\n" + '}'; TTextProtocol prot = new TTextProtocol( new TIOStreamTransport(new ByteArrayInputStream(request.getBytes()))); TMessage header = prot.readMessageBegin(); TApplicationException result = TApplicationException.read(prot); prot.readMessageEnd();/* w w w . j a v a2 s. c o m*/ assertEquals("doDebug", header.name); assertEquals(TMessageType.EXCEPTION, header.type); assertEquals(101, header.seqid); assertEquals(TApplicationException.BAD_SEQUENCE_ID, result.getType()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); prot = new TTextProtocol(new TIOStreamTransport(outputStream)); prot.writeMessageBegin(header); new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, "bad_seq_id").write(prot); prot.writeMessageEnd(); assertJsonEquals(request, new String(outputStream.toByteArray(), StandardCharsets.UTF_8)); }
From source file:org.apache.accumulo.core.rpc.TServiceClientWrapper.java
License:Apache License
@Override protected void receiveBase(TBase<?, ?> result, String methodName) throws TException { TMessage msg = iprot_.readMessageBegin(); if (msg.type == TMessageType.EXCEPTION) { TApplicationException x = new TApplicationException(); x.read(iprot_);/*w w w. ja v a 2 s . co m*/ iprot_.readMessageEnd(); throw x; } if (msg.seqid != seqid_) { throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, String.format( "%s failed: out of sequence response: expected %d but got %d", methodName, seqid_, msg.seqid)); } result.read(iprot_); iprot_.readMessageEnd(); }