]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/java/test/org/apache/thrift/TestMultiplexedProcessor.java
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / lib / java / test / org / apache / thrift / TestMultiplexedProcessor.java
CommitLineData
f67539c2
TL
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package org.apache.thrift;
21
22import static org.mockito.Matchers.any;
23import static org.mockito.Mockito.mock;
24import static org.mockito.Mockito.verify;
25import static org.mockito.Mockito.when;
26
27import org.apache.thrift.protocol.TMessage;
28import org.apache.thrift.protocol.TMessageType;
29import org.apache.thrift.protocol.TProtocol;
30import org.junit.Before;
31import org.junit.Test;
32
33public class TestMultiplexedProcessor {
34 private TMultiplexedProcessor mp;
35 private TProtocol iprot;
36 private TProtocol oprot;
37
38 @Before
39 public void setUp() throws Exception {
40 mp = new TMultiplexedProcessor();
41 iprot = mock(TProtocol.class);
42 oprot = mock(TProtocol.class);
43 }
44
45 @Test(expected = TException.class)
46 public void testWrongMessageType() throws TException {
47 when (iprot.readMessageBegin()).thenReturn(new TMessage("service:func", TMessageType.REPLY, 42));
48 mp.process(iprot, oprot);
49 }
50
51 @Test(expected = TException.class)
52 public void testNoSuchService() throws TException {
53 when(iprot.readMessageBegin()).thenReturn(new TMessage("service:func", TMessageType.CALL, 42));
54
55 mp.process(iprot, oprot);
56 }
57
58 static class StubProcessor implements TProcessor {
59 @Override
60 public void process(TProtocol in, TProtocol out) throws TException {
61 TMessage msg = in.readMessageBegin();
62 if (!"func".equals(msg.name) || msg.type!=TMessageType.CALL || msg.seqid!=42) {
63 throw new TException("incorrect parameters");
64 }
65 out.writeMessageBegin(new TMessage("func", TMessageType.REPLY, 42));
66 }
67 }
68
69 @Test
70 public void testExistingService() throws TException {
71 when(iprot.readMessageBegin()).thenReturn(new TMessage("service:func", TMessageType.CALL, 42));
72 mp.registerProcessor("service", new StubProcessor());
73 mp.process(iprot, oprot);
74 verify(oprot).writeMessageBegin(any(TMessage.class));
75 }
76
77 @Test
78 public void testDefaultService() throws TException {
79 when(iprot.readMessageBegin()).thenReturn(new TMessage("func", TMessageType.CALL, 42));
80 mp.registerDefault(new StubProcessor());
81 mp.process(iprot, oprot);
82 verify(oprot).writeMessageBegin(any(TMessage.class));
83 }
84
85}