1 // Written in D programming language
2 /**
3 *   This module defines rpc client class for testing rpc server.
4 *
5 *   Copyright: © 2014 DSoftOut
6 *   License: Subject to the terms of the MIT license, as written in the included LICENSE file.
7 *   Authors: NCrashed <ncrashed@gmail.com>
8 */
9 module client.client;
10 
11 import std.stdio;
12 import core.time;
13 import vibe.data.json;
14 import vibe.http.rest;
15 import client.rpcapi;
16 import client.test.testcase;
17 import pgator.db.pool;
18 import pgator.db.async.pool;    
19 import pgator.db.pq.libpq;
20 import pgator.db.pq.connection;
21 import dlogg.strict;
22 
23 class RpcClient(T...)
24 {
25     this(string host, string connString, string jsonRpcTable, uint serverPid)
26     {
27         this.jsonRpcTable = jsonRpcTable;
28         this.serverPid = serverPid;
29         api = new RestInterfaceClient!IRpcApi(host);
30         
31         logger = new shared StrictLogger("rpc-client.log");
32         
33         auto postgresApi = new shared PostgreSQL(logger);
34         auto connProvider = new shared PQConnProvider(logger, postgresApi);
35         
36         pool = new shared AsyncPool(logger, connProvider, dur!"seconds"(1), dur!"seconds"(5), dur!"seconds"(3));
37         
38         pool.addServer(connString, 2);
39     }
40     
41     void finalize()
42     {
43         pool.finalize();
44         logger.finalize();
45     }
46     
47     void runTests()
48     {
49         foreach(TestCase; T)
50         {
51             static assert(is(TestCase : ITestCase));
52             auto test = new TestCase();
53             test.run(api, pool, jsonRpcTable, serverPid);
54         }
55     }
56     
57     private 
58     {
59         RestInterfaceClient!IRpcApi api;
60         shared IConnectionPool pool;
61         shared ILogger logger;
62         string jsonRpcTable;
63         uint serverPid;
64     } 
65 }