lttng: Fix a package dependency in control.core
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.core.tests / src / org / eclipse / tracecompass / lttng2 / control / core / tests / relayd / LttngRelayd24Test.java
1 /**********************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial implementation
11 **********************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.control.core.tests.relayd;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertTrue;
18
19 import java.io.DataInputStream;
20 import java.io.DataOutputStream;
21 import java.io.IOException;
22 import java.net.InetAddress;
23 import java.net.Socket;
24 import java.util.List;
25
26 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.ILttngRelaydConnector;
27 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.AttachSessionResponse;
28 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.Command;
29 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.ConnectResponse;
30 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.CreateSessionResponse;
31 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.CreateSessionReturnCode;
32 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.GetNextIndex;
33 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.IndexResponse;
34 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.NextIndexReturnCode;
35 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.SessionResponse;
36 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.StreamResponse;
37 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.commands.ViewerCommand;
38 import org.eclipse.tracecompass.internal.lttng2.control.core.relayd.impl.LttngRelaydConnectorFactory;
39 import org.junit.Test;
40
41 /**
42 * Unit tests for lttng-relayd. It actually allows us to test the API.
43 *
44 * @author Matthew Khouzam
45 */
46 public class LttngRelayd24Test {
47
48 private static final int PACKETS_TO_READ = 100;
49 private static final String ADDRESS = "127.0.0.1"; // change me //$NON-NLS-1$
50 private static final int PORT = 5344;
51
52 private static void getPackets(AttachSessionResponse attachedSession, Socket connection, ILttngRelaydConnector relayD) throws IOException {
53 int numPacketsReceived = 0;
54 DataOutputStream fOutNet = new DataOutputStream(connection.getOutputStream());
55 DataInputStream fInNet = new DataInputStream(connection.getInputStream());
56 while (numPacketsReceived < PACKETS_TO_READ) {
57 for (StreamResponse stream : attachedSession.getStreamList()) {
58 if (stream.getMetadataFlag() != 1) {
59 ConnectResponse connectPayload = new ConnectResponse(fInNet);
60 assertNotNull(connectPayload);
61
62 ViewerCommand connectCommand = new ViewerCommand(Command.VIEWER_GET_NEXT_INDEX, ConnectResponse.SIZE, 0);
63 fOutNet.write(connectCommand.serialize());
64 fOutNet.flush();
65
66 GetNextIndex indexRequest = new GetNextIndex(stream.getId());
67 fOutNet.write(indexRequest.serialize());
68 fOutNet.flush();
69
70 IndexResponse indexReply = new IndexResponse(fInNet);
71 // Nothing else supported for now
72 if (indexReply.getStatus() == NextIndexReturnCode.VIEWER_INDEX_OK) {
73 if (relayD.getPacketFromStream(indexReply, stream.getId()) != null) {
74 numPacketsReceived++;
75 }
76 }
77 }
78 }
79 }
80 }
81
82 /**
83 * Test a connection
84 *
85 * @throws IOException
86 * network timeout?
87 */
88 @Test
89 public void testViewerConnection() throws IOException {
90 InetAddress addr = InetAddress.getByName(ADDRESS);
91 try (Socket connection = new Socket(addr, PORT);
92 ILttngRelaydConnector relayD = LttngRelaydConnectorFactory.getNewConnector(connection);) {
93
94 List<SessionResponse> sessions = relayD.getSessions();
95 assertTrue(sessions.size() > 0);
96 SessionResponse lttngViewerSession = sessions.get(0);
97 assertNotNull(lttngViewerSession);
98 CreateSessionResponse createSession = relayD.createSession();
99 assertEquals(createSession.getStatus(), CreateSessionReturnCode.LTTNG_VIEWER_CREATE_SESSION_OK);
100 AttachSessionResponse attachedSession = relayD.attachToSession(lttngViewerSession);
101
102 String metaData = relayD.getMetadata(attachedSession);
103 assertNotNull(metaData);
104
105 getPackets(attachedSession, connection, relayD);
106 }
107 }
108 }
This page took 0.035048 seconds and 5 git commands to generate.