Disable live tracing feature
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.core.tests / src / org / eclipse / tracecompass / lttng2 / control / core / tests / relayd / LttngRelayd24TestApplication.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.Ignore;
40 import org.junit.Test;
41
42 /**
43 * Test application for lttng-relayd. It actually allows us to test the API.
44 * Written as a Junit test for convenience.
45 *
46 * @author Matthew Khouzam
47 */
48 public class LttngRelayd24TestApplication {
49
50 private static final int PACKETS_TO_READ = 100;
51 private static final String ADDRESS = "127.0.0.1"; // change me //$NON-NLS-1$
52 private static final int PORT = 5344;
53
54 private static void getPackets(AttachSessionResponse attachedSession, Socket connection, ILttngRelaydConnector relayD) throws IOException {
55 int numPacketsReceived = 0;
56 DataOutputStream fOutNet = new DataOutputStream(connection.getOutputStream());
57 DataInputStream fInNet = new DataInputStream(connection.getInputStream());
58 while (numPacketsReceived < PACKETS_TO_READ) {
59 for (StreamResponse stream : attachedSession.getStreamList()) {
60 if (stream.getMetadataFlag() != 1) {
61 ConnectResponse connectPayload = new ConnectResponse(fInNet);
62 assertNotNull(connectPayload);
63
64 ViewerCommand connectCommand = new ViewerCommand(Command.VIEWER_GET_NEXT_INDEX, ConnectResponse.SIZE, 0);
65 fOutNet.write(connectCommand.serialize());
66 fOutNet.flush();
67
68 GetNextIndex indexRequest = new GetNextIndex(stream.getId());
69 fOutNet.write(indexRequest.serialize());
70 fOutNet.flush();
71
72 IndexResponse indexReply = new IndexResponse(fInNet);
73 // Nothing else supported for now
74 if (indexReply.getStatus() == NextIndexReturnCode.VIEWER_INDEX_OK) {
75 if (relayD.getPacketFromStream(indexReply, stream.getId()) != null) {
76 numPacketsReceived++;
77 }
78 }
79 }
80 }
81 }
82 }
83
84 /**
85 * Test a connection
86 *
87 * @throws IOException
88 * network timeout?
89 */
90 @Test
91 @Ignore
92 public void testViewerConnection() throws IOException {
93 InetAddress addr = InetAddress.getByName(ADDRESS);
94 try (Socket connection = new Socket(addr, PORT);
95 ILttngRelaydConnector relayD = LttngRelaydConnectorFactory.getNewConnector(connection);) {
96
97 List<SessionResponse> sessions = relayD.getSessions();
98 assertTrue(sessions.size() > 0);
99 SessionResponse lttngViewerSession = sessions.get(0);
100 assertNotNull(lttngViewerSession);
101 CreateSessionResponse createSession = relayD.createSession();
102 assertEquals(createSession.getStatus(), CreateSessionReturnCode.LTTNG_VIEWER_CREATE_SESSION_OK);
103 AttachSessionResponse attachedSession = relayD.attachToSession(lttngViewerSession);
104
105 String metaData = relayD.getMetadata(attachedSession);
106 assertNotNull(metaData);
107
108 getPackets(attachedSession, connection, relayD);
109 }
110 }
111 }
This page took 0.031705 seconds and 5 git commands to generate.