blob: 4f8275db9793349368a6cecb0d629edc0c2dab10 [file] [log] [blame]
Roger Meier2be7f242012-05-10 09:01:45 +00001/*
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#ifndef _THRIFT_TEST_EVENTLOG_H_
20#define _THRIFT_TEST_EVENTLOG_H_ 1
21
Roger Meier2b1a5282012-05-11 10:12:39 +000022#include <thrift/concurrency/Monitor.h>
Roger Meier2be7f242012-05-10 09:01:45 +000023
Konrad Grochowski16a23a62014-11-13 15:33:38 +010024namespace apache {
25namespace thrift {
26namespace test {
Roger Meier2be7f242012-05-10 09:01:45 +000027
28// Initially I made EventType an enum, but using char* results
29// in much more readable error messages when there is a mismatch.
30// It also lets users of EventLog easily define their own new types.
31// Comparing the literal pointer values should be safe, barring any strange
32// linking setup that results in duplicate symbols.
33typedef const char* EventType;
34
35struct Event {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010036 Event(EventType type, uint32_t connectionId, uint32_t callId, const std::string& message)
37 : type(type), connectionId(connectionId), callId(callId), message(message) {}
Roger Meier2be7f242012-05-10 09:01:45 +000038
39 EventType type;
Konrad Grochowski16a23a62014-11-13 15:33:38 +010040 uint32_t connectionId;
41 uint32_t callId;
42 std::string message;
Roger Meier2be7f242012-05-10 09:01:45 +000043};
44
45class EventLog {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010046public:
Roger Meier2be7f242012-05-10 09:01:45 +000047 static EventType ET_LOG_END;
48 static EventType ET_CONN_CREATED;
49 static EventType ET_CONN_DESTROYED;
50 static EventType ET_CALL_STARTED;
51 static EventType ET_CALL_FINISHED;
52 static EventType ET_PROCESS;
53 static EventType ET_PRE_READ;
54 static EventType ET_POST_READ;
55 static EventType ET_PRE_WRITE;
56 static EventType ET_POST_WRITE;
57 static EventType ET_ASYNC_COMPLETE;
58 static EventType ET_HANDLER_ERROR;
59
60 static EventType ET_CALL_INCREMENT_GENERATION;
61 static EventType ET_CALL_GET_GENERATION;
62 static EventType ET_CALL_ADD_STRING;
63 static EventType ET_CALL_GET_STRINGS;
64 static EventType ET_CALL_GET_DATA_WAIT;
65 static EventType ET_CALL_ONEWAY_WAIT;
66 static EventType ET_CALL_UNEXPECTED_EXCEPTION_WAIT;
67 static EventType ET_CALL_EXCEPTION_WAIT;
68 static EventType ET_WAIT_RETURN;
69 static EventType ET_CALL_SET_VALUE;
70 static EventType ET_CALL_GET_VALUE;
71
72 EventLog();
73
Konrad Grochowski16a23a62014-11-13 15:33:38 +010074 void append(EventType type,
75 uint32_t connectionId,
76 uint32_t callId,
Roger Meier2be7f242012-05-10 09:01:45 +000077 const std::string& message = "");
78
79 Event waitForEvent(int64_t timeout = 500);
80 Event waitForConnEvent(uint32_t connId, int64_t timeout = 500);
81
Konrad Grochowski16a23a62014-11-13 15:33:38 +010082protected:
Roger Meier2be7f242012-05-10 09:01:45 +000083 typedef std::list<Event> EventList;
84
85 concurrency::Monitor monitor_;
86 EventList events_;
87 uint32_t id_;
88
89 static uint32_t nextId_;
90};
Konrad Grochowski16a23a62014-11-13 15:33:38 +010091}
92}
93} // apache::thrift::test
Roger Meier2be7f242012-05-10 09:01:45 +000094
95#endif // _THRIFT_TEST_EVENTLOG_H_