aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus_test/src/tests/error/JavaClient.java
blob: 764cf4c1d865717f7ee2595220a9381971e93d74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
import com.yahoo.messagebus.*;
import com.yahoo.messagebus.test.*;
import com.yahoo.config.*;
import com.yahoo.messagebus.routing.*;
import com.yahoo.messagebus.network.*;
import com.yahoo.messagebus.network.rpc.*;
import com.yahoo.messagebus.network.rpc.test.*;
import java.util.Arrays;
import java.util.logging.*;

public class JavaClient {

    private static Logger log = Logger.getLogger(JavaClient.class.getName());

    public static void main(String[] args) {
        try {
	    RPCMessageBus mb = new RPCMessageBus(
		Arrays.asList((Protocol)new SimpleProtocol()),
                new RPCNetworkParams()
                .setIdentity(new Identity("server/java"))
		.setSlobrokConfigId("file:slobrok.cfg"),
		"file:routing.cfg");

            Receptor src = new Receptor();
            Message msg = null;
            Reply reply = null;

            SourceSession session = mb.getMessageBus().createSourceSession(src, new SourceSessionParams().setTimeout(300));
            for (int i = 0; i < 10; i++) {
                msg = new SimpleMessage("test");
                msg.getTrace().setLevel(9);
                session.send(msg, "test");
                reply = src.getReply(60);
                if (reply == null) {
                    System.err.println("JAVA-CLIENT: no reply");
                } else {
                    System.err.println("JAVA-CLIENT:\n"  + reply.getTrace());
                    if (reply.getNumErrors() == 2) {
                        break;
                    }
                }
                Thread.sleep(1000);
            }
            if (reply == null) {
                System.err.println("JAVA-CLIENT: no reply");
                System.exit(1);
            }
            if (reply.getNumErrors() != 2 ||
                reply.getError(0).getCode() != ErrorCode.APP_FATAL_ERROR + 1 ||
                reply.getError(1).getCode() != ErrorCode.APP_FATAL_ERROR + 2 ||
                !reply.getError(0).getMessage().equals("ERR 1") ||
                !reply.getError(1).getMessage().equals("ERR 2"))
            {
                System.err.printf("JAVA-CLIENT: wrong errors\n");
                System.exit(1);
            }
            session.destroy();
            mb.destroy();
        } catch (Exception e) {
            log.log(Level.SEVERE, "JAVA-CLIENT: Failed", e);
            System.exit(1);
        }
    }
}