VPP-330 Track pending map-requests with a fifo
[vpp.git] / vpp-api / java / jvpp / org / openvpp / jvpp / test / OnErrorCallbackTest.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openvpp.jvpp.test;
18
19 import org.openvpp.jvpp.JVpp;
20 import org.openvpp.jvpp.JVppImpl;
21 import org.openvpp.jvpp.VppCallbackException;
22 import org.openvpp.jvpp.VppJNIConnection;
23 import org.openvpp.jvpp.callback.GetNodeIndexCallback;
24 import org.openvpp.jvpp.callback.ShowVersionCallback;
25 import org.openvpp.jvpp.dto.*;
26
27 public class OnErrorCallbackTest {
28
29     private static class TestCallback implements GetNodeIndexCallback, ShowVersionCallback{
30
31         @Override
32         public void onGetNodeIndexReply(final GetNodeIndexReply msg) {
33             System.out.printf("Received GetNodeIndexReply: context=%d, nodeIndex=%d\n",
34                     msg.context, msg.nodeIndex);
35         }
36         @Override
37         public void onShowVersionReply(final ShowVersionReply msg) {
38             System.out.printf("Received ShowVersionReply: context=%d, program=%s, version=%s, " +
39                     "buildDate=%s, buildDirectory=%s\n",
40                     msg.context, new String(msg.program), new String(msg.version),
41                     new String(msg.buildDate), new String(msg.buildDirectory));
42         }
43
44         @Override
45         public void onError(VppCallbackException ex) {
46             System.out.printf("Received onError exception: call=%s, context=%d, retval=%d\n", ex.getMethodName(), ex.getCtxId(), ex.getErrorCode());
47         }
48     }
49
50     private static void testCallbackApi() throws Exception {
51         System.out.println("Testing Java callback API");
52         JVpp jvpp = new JVppImpl(new VppJNIConnection("CallbackApiTest"));
53         jvpp.connect(new TestCallback());
54         System.out.println("Successfully connected to VPP");
55
56         System.out.println("Sending ShowVersion request...");
57         jvpp.send(new ShowVersion());
58
59         System.out.println("Sending GetNodeIndex request...");
60         GetNodeIndex getNodeIndexRequest = new GetNodeIndex();
61         getNodeIndexRequest.nodeName = "dummyNode".getBytes();
62         jvpp.send(getNodeIndexRequest);
63
64         Thread.sleep(5000);
65
66         System.out.println("Disconnecting...");
67         jvpp.close();
68         Thread.sleep(1000);
69     }
70
71     public static void main(String[] args) throws Exception {
72         testCallbackApi();
73     }
74 }