libtasks Documentation  1.6
test_uwsgi_thrift.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #include <arpa/inet.h>
9 #include <csignal>
10 #include <thrift/protocol/TBinaryProtocol.h>
11 #include <thrift/transport/THttpClient.h>
12 #include <boost/shared_ptr.hpp>
13 
14 #include <tasks/net/acceptor.h>
16 #include <tasks/logging.h>
17 
18 #include "test_uwsgi_thrift.h"
19 
20 void ip_service::lookup(response_type& result, const int32_t /* ipv4 */, const ipv6_type& /* ipv6 */) {
21  key_value_type kv;
22  id_name_type val;
23  kv.key.id = 1;
24  kv.key.name = "city";
25  val.id = 123456;
26  val.name = "Berlin";
27  kv.values.push_back(val);
28  result.key_values.push_back(kv);
29  kv.values.clear();
30 
31  kv.key.id = 2;
32  kv.key.name = "country";
33  val.id = 3345677;
34  val.name = "Germany";
35  kv.values.push_back(val);
36  result.key_values.push_back(kv);
37 }
38 
40  using namespace tasks;
41  using namespace tasks::net;
42 
45 
46  using namespace apache::thrift::protocol;
47  using namespace apache::thrift::transport;
48  boost::shared_ptr<THttpClient> transport(new THttpClient("127.0.0.1", 18080, "/test1"));
49  boost::shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport));
50  IpServiceClient client(protocol);
51 
52  bool success = true;
53  try {
54  transport->open();
55 
56  int32_t ip = 123456789;
57  ipv6_type ipv6;
58  response_type r;
59  client.lookup(r, ip, ipv6);
60 
61  CPPUNIT_ASSERT(r.key_values.size() == 2);
62  CPPUNIT_ASSERT(r.key_values[0].key.id == 1);
63  CPPUNIT_ASSERT(r.key_values[0].key.name == "city");
64  CPPUNIT_ASSERT(r.key_values[0].values.size() == 1);
65  CPPUNIT_ASSERT(r.key_values[0].values[0].id == 123456);
66  CPPUNIT_ASSERT(r.key_values[0].values[0].name == "Berlin");
67  CPPUNIT_ASSERT(r.key_values[1].key.id == 2);
68  CPPUNIT_ASSERT(r.key_values[1].key.name == "country");
69  CPPUNIT_ASSERT(r.key_values[1].values.size() == 1);
70  CPPUNIT_ASSERT(r.key_values[1].values[0].id == 3345677);
71  CPPUNIT_ASSERT(r.key_values[1].values[0].name == "Germany");
72 
73  transport->close();
74  } catch (TTransportException& e) {
75  success = false;
76  }
77  CPPUNIT_ASSERT(success);
78 }
static void add_task(net_io_task *task)
Definition: net_io_task.cpp:40
std::unique_ptr< tasks::net_io_task > m_srv
void lookup(response_type &result, const int32_t ipv4, const ipv6_type &ipv6)
Definition: ip_service.cpp:15