-
Notifications
You must be signed in to change notification settings - Fork 4
/
trash.clj
105 lines (81 loc) · 2.62 KB
/
trash.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
;; TODO: SSL tests
#_
(def ssl-context
(ssl/ssl-context "../certs/client.key"
"../certs/client.crt"
"../certs/root.crt"))
#_
(def ^:dynamic *CONFIG*
{:host "127.0.0.1"
:port 10130
;; :port 15432 ;; ssl
:user "test"
:password "test"
:database "test"
;; :use-ssl? true
;; :ssl-context ssl-context
})
(def PORT_SSL
(some-> "PG_PORT_SSL"
System/getenv
Integer/parseInt))
(def OVERRIDES
{PORT_SSL
{:ssl? true
:ssl-context
(ssl/context {:key-file "../certs/client.key"
:cert-file "../certs/client.crt"
:ca-cert-file "../certs/root.crt"})}})
(defn isSSL? []
(and PORT_SSL (= *PORT* PORT_SSL)))
(let [buf
(new java.io.ByteArrayOutputStream)
rows
(for [x (range 100000)]
[x
(str "name" x)
(LocalDateTime/now)])]
(with-open [writer (-> buf
io/writer)]
(csv/write-csv writer rows))
(pg/copy-in conn
"copy aaa (id, name, created_at) from STDIN WITH (FORMAT CSV)"
(-> buf (.toByteArray) io/input-stream)))
[{:title "test1",
:id 4,
:created_at
#object[java.time.OffsetDateTime 0x31340eb6 "2024-01-17T21:57:58.660012+03:00"]}
{:title "test2",
:id 5,
:created_at
#object[java.time.OffsetDateTime 0x11a5aab5 "2024-01-17T21:57:58.660012+03:00"]}
{:title "test3",
:id 6,
:created_at
#object[java.time.OffsetDateTime 0x3ee200bc "2024-01-17T21:57:58.660012+03:00"]}]
{:title "test2",
:id 5,
:created_at
#object[java.time.OffsetDateTime 0x21782713 "2024-01-17T21:57:58.660012+03:00"]}
private boolean _is_used_too_long (final long startTime) {
return System.currentTimeMillis() - startTime > 123;
}
private void _pre_foo_bar () {
Connection conn;
for (Map.Entry<UUID, Long> entry : connUsedSince.entrySet()) {
if (_is_used_too_long(entry.getValue())) {
conn = connsUsed.get(entry.getKey());
final String message = String.format(
"Connection %s has been considered as leaked, closing",
conn.getId()
);
logger.log(config.logLevel(), message);
removeUsed(conn);
utilizeConnection(conn);
}
}
}
private final Map<UUID, Long> connUsedSince;
this.connUsedSince = new HashMap<>(config.poolMaxSize());
connUsedSince.remove(conn.getId());
connUsedSince.put(conn.getId(), System.currentTimeMillis());