1 /*
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 
22 #include <thrift/concurrency/Monitor.h>
23 
24 namespace apache {
25 namespace thrift {
26 namespace test {
27 
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.
33 typedef const char* EventType;
34 
35 struct Event {
EventEvent36   Event(EventType type, uint32_t connectionId, uint32_t callId, const std::string& message)
37     : type(type), connectionId(connectionId), callId(callId), message(message) {}
38 
39   EventType type;
40   uint32_t connectionId;
41   uint32_t callId;
42   std::string message;
43 };
44 
45 class EventLog {
46 public:
47   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 
74   void append(EventType type,
75               uint32_t connectionId,
76               uint32_t callId,
77               const std::string& message = "");
78 
79   Event waitForEvent(int64_t timeout = 500);
80   Event waitForConnEvent(uint32_t connId, int64_t timeout = 500);
81 
82 protected:
83   typedef std::list<Event> EventList;
84 
85   concurrency::Monitor monitor_;
86   EventList events_;
87   uint32_t id_;
88 
89   static uint32_t nextId_;
90 };
91 }
92 }
93 } // apache::thrift::test
94 
95 #endif // _THRIFT_TEST_EVENTLOG_H_
96