Mercurial > hg > ltpda-connection-manager
annotate test_ltpda_connection_manager.m @ 5:35f1cfcaa5a9
Add crude Java GUI.
author | Daniele Nicolodi <daniele@science.unitn.it> |
---|---|
date | Wed, 02 Jun 2010 17:29:18 +0200 |
parents | d5fef23867bb |
children |
rev | line source |
---|---|
0
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
1 function test_ltpda_connection_manager() |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
2 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
3 % change with valid credentials |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
4 host = '127.0.0.1'; % sometimes using localhost causes problems |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
5 db = 'one'; |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
6 user = 'daniele'; |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
7 passwd = 'daniele'; |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
8 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
9 % hack user properties |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
10 p = getappdata(0, 'LTPDApreferences'); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
11 p.cm.credentialsExpiry = 120; % seconds |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
12 p.cm.cachePassword = 2; % 0=no 1=yes 2=ask |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
13 p.cm.maxConnectionsNumber = 10; |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
14 setappdata(0, 'LTPDApreferences', p); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
15 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
16 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
17 % reset |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
18 setappdata(0, 'LTPDAConnectionManager', []); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
19 % connection manager |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
20 cm = LTPDAConnectionManager(); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
21 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
22 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
23 % add credentials |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
24 n = numel(cm.credentials); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
25 cm.add(credentials(host, 'db', 'user', 'passwd')); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
26 assert(numel(cm.credentials) == n+1); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
27 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
28 % try again |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
29 cm.add(credentials(host, 'db', 'user', 'passwd')); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
30 % just updated previous entry |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
31 assert(numel(cm.credentials) == n+1); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
32 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
33 % add other credentials |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
34 cm.add(credentials('host', 'db')); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
35 assert(numel(cm.credentials) == n+2); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
36 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
37 % add user |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
38 cm.add(credentials('host', 'db', 'user')); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
39 assert(numel(cm.credentials) == n+2); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
40 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
41 % add password |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
42 cm.add(credentials('host', 'db', 'user', 'passwd')); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
43 assert(numel(cm.credentials) == n+2); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
44 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
45 % add the oned will be used now on |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
46 cm.add(credentials(host, db, user, passwd)); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
47 assert(numel(cm.credentials) == n+3); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
48 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
49 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
50 % use the credentials cache |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
51 c = cm.connect(host, db); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
52 % one connection in the pool |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
53 assert(cm.count() == 1); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
54 c.close(); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
55 % still there |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
56 assert(numel(cm.connections) == 1); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
57 n = cm.count(); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
58 % count has the side effect of removing closed connections from the pool |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
59 assert(n == 0); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
60 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
61 % open two connections |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
62 c1 = cm.connect(host, db); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
63 c2 = cm.connect(host, db, user); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
64 % one connection in the pool |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
65 assert(numel(cm.connections) == 2); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
66 % even when we remove the closed ones |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
67 assert(cm.count() == 2); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
68 % clean up |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
69 c1.close(); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
70 c2.close(); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
71 % no more connections in the pool |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
72 assert(cm.count() == 0); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
73 assert(numel(cm.connections) == 0); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
74 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
75 % plist parameters |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
76 c = cm.connect(plist('hostname', host, 'database', db)); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
77 % one more connection in the pool |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
78 assert(numel(cm.connections) == 1); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
79 % clen up |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
80 c.close(); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
81 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
82 % create a connection |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
83 c1 = cm.connect(host, db); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
84 n = cm.count(); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
85 % specify it as connction parameter |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
86 c2 = cm.connect(plist('connection', c1)); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
87 % we should get back the same connection |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
88 assert(c2 == c1); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
89 % it should not have been added to the connection pool |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
90 assert(numel(cm.connections) == n); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
91 % clean up |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
92 c1.close(); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
93 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
94 % no connections in the pool |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
95 assert(cm.count() == 0); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
96 assert(numel(cm.connections) == 0); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
97 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
98 % open a bunch of connections |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
99 c = cm.connect(host, db); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
100 c = cm.connect(host, db); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
101 c = cm.connect(host, db); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
102 c = cm.connect(host, db); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
103 c = cm.connect(host, db); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
104 assert(numel(cm.connections) == 5); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
105 assert(cm.count() == 5); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
106 % close them all |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
107 cm.close(); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
108 % check |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
109 assert(cm.count() == 0); |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
110 |
d5fef23867bb
First workig implementation.
Daniele Nicolodi <daniele@science.unitn.it>
parents:
diff
changeset
|
111 end |