summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/test/threads
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/jaegertracing/thrift/test/threads
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/thrift/test/threads')
-rw-r--r--src/jaegertracing/thrift/test/threads/Makefile63
-rw-r--r--src/jaegertracing/thrift/test/threads/ThreadsClient.cpp69
-rw-r--r--src/jaegertracing/thrift/test/threads/ThreadsServer.cpp148
-rw-r--r--src/jaegertracing/thrift/test/threads/ThreadsTest.thrift28
4 files changed, 308 insertions, 0 deletions
diff --git a/src/jaegertracing/thrift/test/threads/Makefile b/src/jaegertracing/thrift/test/threads/Makefile
new file mode 100644
index 000000000..df7239691
--- /dev/null
+++ b/src/jaegertracing/thrift/test/threads/Makefile
@@ -0,0 +1,63 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Default target is everything
+
+ifndef thrift_home
+thrift_home=../../
+endif #thrift_home
+
+target: all
+
+ifndef boost_home
+boost_home=/usr/local/include/boost-1_33_1
+endif #boost_home
+target: all
+
+include_paths = $(thrift_home)/lib/cpp/src \
+ $(boost_home)
+
+include_flags = $(patsubst %,-I%, $(include_paths))
+
+# Tools
+ifndef THRIFT
+THRIFT = ../../compiler/cpp/thrift
+endif # THRIFT
+
+CC = g++
+LD = g++
+
+# Compiler flags
+LFL = -L$(thrift_home)/lib/cpp/.libs -lthrift
+CCFL = -Wall -O3 -g -I./gen-cpp $(include_flags)
+CFL = $(CCFL) $(LFL)
+
+all: server client
+
+stubs: ThreadsTest.thrift
+ $(THRIFT) --gen cpp --gen py ThreadsTest.thrift
+
+server: stubs
+ $(CC) -o ThreadsServer $(CFL) ThreadsServer.cpp ./gen-cpp/ThreadsTest.cpp ./gen-cpp/ThreadsTest_types.cpp
+
+client: stubs
+ $(CC) -o ThreadsClient $(CFL) ThreadsClient.cpp ./gen-cpp/ThreadsTest.cpp ./gen-cpp/ThreadsTest_types.cpp
+
+clean:
+ $(RM) -r *.o ThreadsServer ThreadsClient gen-cpp gen-py
diff --git a/src/jaegertracing/thrift/test/threads/ThreadsClient.cpp b/src/jaegertracing/thrift/test/threads/ThreadsClient.cpp
new file mode 100644
index 000000000..e8bd79e69
--- /dev/null
+++ b/src/jaegertracing/thrift/test/threads/ThreadsClient.cpp
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// This autogenerated skeleton file illustrates how to build a server.
+// You should copy it to another filename to avoid overwriting it.
+
+#include "ThreadsTest.h"
+#include <thrift/protocol/TBinaryProtocol.h>
+#include <thrift/server/TThreadPoolServer.h>
+#include <thrift/transport/TSocket.h>
+#include <thrift/transport/TTransportUtils.h>
+#include <thrift/concurrency/Monitor.h>
+#include <thrift/concurrency/ThreadManager.h>
+#include <thrift/concurrency/ThreadFactory.h>
+#if _WIN32
+ #include <thrift/windows/TWinsockSingleton.h>
+#endif
+
+using boost::shared_ptr;
+using namespace apache::thrift;
+using namespace apache::thrift::protocol;
+using namespace apache::thrift::transport;
+using namespace apache::thrift::server;
+using namespace apache::thrift::concurrency;
+
+int main(int argc, char **argv) {
+#if _WIN32
+ transport::TWinsockSingleton::create();
+#endif
+ int port = 9090;
+ std::string host = "localhost";
+
+ shared_ptr<TTransport> transport(new TSocket(host, port));
+ shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
+
+ transport->open();
+
+ ThreadsTestClient client(protocol);
+ int val;
+ val = client.threadOne(5);
+ fprintf(stderr, "%d\n", val);
+ val = client.stop();
+ fprintf(stderr, "%d\n", val);
+ val = client.threadTwo(5);
+ fprintf(stderr, "%d\n", val);
+
+ transport->close();
+
+ fprintf(stderr, "done.\n");
+
+ return 0;
+}
+
diff --git a/src/jaegertracing/thrift/test/threads/ThreadsServer.cpp b/src/jaegertracing/thrift/test/threads/ThreadsServer.cpp
new file mode 100644
index 000000000..3811b60c5
--- /dev/null
+++ b/src/jaegertracing/thrift/test/threads/ThreadsServer.cpp
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// This autogenerated skeleton file illustrates how to build a server.
+// You should copy it to another filename to avoid overwriting it.
+
+#include "ThreadsTest.h"
+#include <thrift/protocol/TBinaryProtocol.h>
+#include <thrift/server/TThreadPoolServer.h>
+#include <thrift/server/TThreadedServer.h>
+#include <thrift/transport/TServerSocket.h>
+#include <thrift/transport/TTransportUtils.h>
+#include <thrift/concurrency/Monitor.h>
+#include <thrift/concurrency/ThreadManager.h>
+#include <thrift/concurrency/ThreadFactory.h>
+#if _WIN32
+ #include <thrift/windows/TWinsockSingleton.h>
+#endif
+
+using boost::shared_ptr;
+using namespace apache::thrift;
+using namespace apache::thrift::protocol;
+using namespace apache::thrift::transport;
+using namespace apache::thrift::server;
+using namespace apache::thrift::concurrency;
+
+
+class ThreadsTestHandler : virtual public ThreadsTestIf {
+ public:
+ ThreadsTestHandler() {
+ // Your initialization goes here
+ }
+
+ int32_t threadOne(const int32_t sleep) {
+ // Your implementation goes here
+ printf("threadOne\n");
+ go2sleep(1, sleep);
+ return 1;
+ }
+
+ int32_t threadTwo(const int32_t sleep) {
+ // Your implementation goes here
+ printf("threadTwo\n");
+ go2sleep(2, sleep);
+ return 1;
+ }
+
+ int32_t threadThree(const int32_t sleep) {
+ // Your implementation goes here
+ printf("threadThree\n");
+ go2sleep(3, sleep);
+ return 1;
+ }
+
+ int32_t threadFour(const int32_t sleep) {
+ // Your implementation goes here
+ printf("threadFour\n");
+ go2sleep(4, sleep);
+ return 1;
+ }
+
+ int32_t stop() {
+ printf("stop\n");
+ server_->stop();
+ return 1;
+ }
+
+ void setServer(boost::shared_ptr<TServer> server) {
+ server_ = server;
+ }
+
+protected:
+ void go2sleep(int thread, int seconds) {
+ Monitor m;
+ Synchronized s(m);
+ for (int i = 0; i < seconds; ++i) {
+ fprintf(stderr, "Thread %d: sleep %d\n", thread, i);
+ try {
+ m.wait(1000);
+ } catch(const TimedOutException&) {
+ }
+ }
+ fprintf(stderr, "THREAD %d DONE\n", thread);
+ }
+
+private:
+ boost::shared_ptr<TServer> server_;
+
+};
+
+int main(int argc, char **argv) {
+#if _WIN32
+ transport::TWinsockSingleton::create();
+#endif
+ int port = 9090;
+ shared_ptr<ThreadsTestHandler> handler(new ThreadsTestHandler());
+ shared_ptr<TProcessor> processor(new ThreadsTestProcessor(handler));
+ shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
+ shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
+ shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
+
+ /*
+ shared_ptr<ThreadManager> threadManager =
+ ThreadManager::newSimpleThreadManager(10);
+ shared_ptr<ThreadFactory> threadFactory =
+ shared_ptr<ThreadFactory>(new ThreadFactory());
+ threadManager->threadFactory(threadFactory);
+ threadManager->start();
+
+ shared_ptr<TServer> server =
+ shared_ptr<TServer>(new TThreadPoolServer(processor,
+ serverTransport,
+ transportFactory,
+ protocolFactory,
+ threadManager));
+ */
+
+ shared_ptr<TServer> server =
+ shared_ptr<TServer>(new TThreadedServer(processor,
+ serverTransport,
+ transportFactory,
+ protocolFactory));
+
+ handler->setServer(server);
+
+ server->serve();
+
+ fprintf(stderr, "done.\n");
+
+ return 0;
+}
+
diff --git a/src/jaegertracing/thrift/test/threads/ThreadsTest.thrift b/src/jaegertracing/thrift/test/threads/ThreadsTest.thrift
new file mode 100644
index 000000000..caa934605
--- /dev/null
+++ b/src/jaegertracing/thrift/test/threads/ThreadsTest.thrift
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+service ThreadsTest {
+ i32 threadOne(1: i32 sleep=15),
+ i32 threadTwo(2: i32 sleep=15),
+ i32 threadThree(3: i32 sleep=15),
+ i32 threadFour(4: i32 sleep=15)
+
+ i32 stop();
+
+}