1
- package com .twitter .finagle .postgres . integration
1
+ package com .twitter .finagle .postgres
2
2
3
3
import java .sql .Timestamp
4
4
import java .time .Instant
5
5
6
- import com .twitter .finagle .postgres . _
6
+ import com .twitter .finagle .{ Postgres , Status }
7
7
import com .twitter .finagle .postgres .codec .ServerError
8
- import com .twitter .finagle .Postgres
9
- import com .twitter .finagle .Status
10
- import com .twitter .util .Await
11
- import com .twitter .util .Duration
8
+ import com .twitter .util .{Await , Duration }
12
9
13
- object IntegrationSpec {
10
+ object BaseIntegrationSpec {
14
11
val pgTestTable = " finagle_test"
15
12
}
16
13
17
- class IntegrationSpec extends EmbeddedPgSqlSpec {
14
+ abstract class BaseIntegrationSpec ( version : String ) extends EmbeddedPgSqlSpec {
18
15
19
16
val queryTimeout = Duration .fromSeconds(2 )
20
17
@@ -29,7 +26,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
29
26
}
30
27
31
28
def cleanDb (client : PostgresClient ): Unit = {
32
- val dropQuery = client.executeUpdate(" DROP TABLE IF EXISTS %s" .format(IntegrationSpec .pgTestTable))
29
+ val dropQuery = client.executeUpdate(" DROP TABLE IF EXISTS %s" .format(BaseIntegrationSpec .pgTestTable))
33
30
val response = Await .result(dropQuery, queryTimeout)
34
31
35
32
response must equal(OK (1 ))
@@ -43,7 +40,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
43
40
| timestamp_field TIMESTAMP WITH TIME ZONE,
44
41
| bool_field BOOLEAN
45
42
|)
46
- """ .stripMargin.format(IntegrationSpec .pgTestTable))
43
+ """ .stripMargin.format(BaseIntegrationSpec .pgTestTable))
47
44
val response2 = Await .result(createTableQuery, queryTimeout)
48
45
response2 must equal(OK (1 ))
49
46
}
@@ -56,21 +53,21 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
56
53
| ('hello', 5557, -4.51, '2015-01-08 12:55:12-0800', TRUE),
57
54
| ('hello', 7787, -42.51, '2013-12-24 07:01:00-0800', FALSE),
58
55
| ('goodbye', 4567, 15.8, '2015-01-09 16:55:12+0500', FALSE)
59
- """ .stripMargin.format(IntegrationSpec .pgTestTable))
56
+ """ .stripMargin.format(BaseIntegrationSpec .pgTestTable))
60
57
61
58
val response = Await .result(insertDataQuery, queryTimeout)
62
59
63
60
response must equal(OK (4 ))
64
61
}
65
62
66
- " A postgres client" should {
63
+ s " A postgres client against Postgresql v $version " should {
67
64
" insert and select rows" in {
68
65
val client = getClient
69
66
cleanDb(client)
70
67
insertSampleData(client)
71
68
72
69
val selectQuery = client.select(
73
- " SELECT * FROM %s WHERE str_field='hello' ORDER BY timestamp_field" .format(IntegrationSpec .pgTestTable)
70
+ " SELECT * FROM %s WHERE str_field='hello' ORDER BY timestamp_field" .format(BaseIntegrationSpec .pgTestTable)
74
71
)(
75
72
identity)
76
73
@@ -103,7 +100,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
103
100
" SELECT * FROM %s WHERE str_field='xxxx' ORDER BY timestamp_field" .
104
101
format(
105
102
106
- IntegrationSpec .pgTestTable)
103
+ BaseIntegrationSpec .pgTestTable)
107
104
)(identity)
108
105
109
106
val
@@ -121,7 +118,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
121
118
122
119
val updateQuery = client.executeUpdate(
123
120
124
- " UPDATE %s SET str_field='hello_updated' where int_field=4567" .format(IntegrationSpec .pgTestTable)
121
+ " UPDATE %s SET str_field='hello_updated' where int_field=4567" .format(BaseIntegrationSpec .pgTestTable)
125
122
)
126
123
127
124
val response = Await .
@@ -132,7 +129,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
132
129
133
130
val selectQuery = client.select(
134
131
135
- " SELECT * FROM %s WHERE str_field='hello_updated'" .format(IntegrationSpec .pgTestTable)
132
+ " SELECT * FROM %s WHERE str_field='hello_updated'" .format(BaseIntegrationSpec .pgTestTable)
136
133
)(
137
134
138
135
identity)
@@ -152,15 +149,15 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
152
149
153
150
val updateQuery = client.executeUpdate(
154
151
" DELETE FROM %s WHERE str_field='hello'"
155
- .format(IntegrationSpec .pgTestTable)
152
+ .format(BaseIntegrationSpec .pgTestTable)
156
153
)
157
154
158
155
val response = Await .result(updateQuery, queryTimeout)
159
156
160
157
response must equal(OK (3 ))
161
158
162
159
val selectQuery = client.select(
163
- " SELECT * FROM %s" .format(IntegrationSpec .pgTestTable)
160
+ " SELECT * FROM %s" .format(BaseIntegrationSpec .pgTestTable)
164
161
)(identity)
165
162
166
163
val resultRows = Await .result(selectQuery, queryTimeout)
@@ -176,7 +173,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
176
173
insertSampleData(client)
177
174
178
175
val preparedQuery = client.prepareAndQuery(
179
- " SELECT * FROM %s WHERE str_field=$1 AND bool_field=$2" .format(IntegrationSpec .pgTestTable),
176
+ " SELECT * FROM %s WHERE str_field=$1 AND bool_field=$2" .format(BaseIntegrationSpec .pgTestTable),
180
177
Param (" hello" ),
181
178
Param (true ))(identity)
182
179
@@ -199,14 +196,14 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
199
196
insertSampleData(client)
200
197
201
198
val preparedQuery = client.prepareAndExecute(
202
- " UPDATE %s SET str_field = $1 where int_field = 4567" .format(IntegrationSpec .pgTestTable),
199
+ " UPDATE %s SET str_field = $1 where int_field = 4567" .format(BaseIntegrationSpec .pgTestTable),
203
200
Param (" hello_updated" )
204
201
)
205
202
206
203
val numRows = Await .result(preparedQuery)
207
204
208
205
val resultRows = Await .result(client.select(
209
- " SELECT * from %s WHERE str_field = 'hello_updated' AND int_field = 4567" .format(IntegrationSpec .pgTestTable)
206
+ " SELECT * from %s WHERE str_field = 'hello_updated' AND int_field = 4567" .format(BaseIntegrationSpec .pgTestTable)
210
207
)(identity))
211
208
212
209
resultRows.size must equal(numRows)
@@ -219,14 +216,14 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
219
216
220
217
221
218
val preparedQuery = client.prepareAndExecute(
222
- " UPDATE %s SET str_field = $1 where int_field = 4567" .format(IntegrationSpec .pgTestTable),
219
+ " UPDATE %s SET str_field = $1 where int_field = 4567" .format(BaseIntegrationSpec .pgTestTable),
223
220
Some (" hello_updated_some" )
224
221
)
225
222
226
223
val numRows = Await .result(preparedQuery)
227
224
228
225
val resultRows = Await .result(client.select(
229
- " SELECT * from %s WHERE str_field = 'hello_updated_some' AND int_field = 4567" .format(IntegrationSpec .pgTestTable)
226
+ " SELECT * from %s WHERE str_field = 'hello_updated_some' AND int_field = 4567" .format(BaseIntegrationSpec .pgTestTable)
230
227
)(identity))
231
228
232
229
resultRows.size must equal(numRows)
@@ -239,14 +236,14 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
239
236
240
237
241
238
val preparedQuery = client.prepareAndExecute(
242
- " UPDATE %s SET str_field = $1 where int_field = 4567" .format(IntegrationSpec .pgTestTable),
239
+ " UPDATE %s SET str_field = $1 where int_field = 4567" .format(BaseIntegrationSpec .pgTestTable),
243
240
None : Option [String ]
244
241
)
245
242
246
243
val numRows = Await .result(preparedQuery)
247
244
248
245
val resultRows = Await .result(client.select(
249
- " SELECT * from %s WHERE str_field IS NULL AND int_field = 4567" .format(IntegrationSpec .pgTestTable)
246
+ " SELECT * from %s WHERE str_field IS NULL AND int_field = 4567" .format(BaseIntegrationSpec .pgTestTable)
250
247
)(identity))
251
248
252
249
resultRows.size must equal(numRows)
@@ -259,7 +256,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
259
256
260
257
261
258
val preparedQuery = client.prepareAndQuery(
262
- " UPDATE %s SET str_field = $1 where int_field = 4567 RETURNING *" .format(IntegrationSpec .pgTestTable),
259
+ " UPDATE %s SET str_field = $1 where int_field = 4567 RETURNING *" .format(BaseIntegrationSpec .pgTestTable),
263
260
Param (" hello_updated" )
264
261
)(identity)
265
262
@@ -275,12 +272,12 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
275
272
insertSampleData(client)
276
273
277
274
Await .result(client.prepareAndExecute(
278
- s """ INSERT INTO ${IntegrationSpec .pgTestTable}
275
+ s """ INSERT INTO ${BaseIntegrationSpec .pgTestTable}
279
276
VALUES ('delete', 9012, 15.8, '2015-01-09 16:55:12+0500', FALSE) """
280
277
))
281
278
282
279
val preparedQuery = client.prepareAndQuery (
283
- " DELETE FROM %s where int_field = 9012 RETURNING *" .format(IntegrationSpec .pgTestTable)
280
+ " DELETE FROM %s where int_field = 9012 RETURNING *" .format(BaseIntegrationSpec .pgTestTable)
284
281
)(identity)
285
282
286
283
val resultRows = Await .result(preparedQuery)
@@ -295,7 +292,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
295
292
cleanDb(client)
296
293
insertSampleData(client)
297
294
val preparedQuery = client.prepareAndQuery(
298
- " UPDATE %s SET str_field = $1 where str_field = $2 RETURNING *" .format(IntegrationSpec .pgTestTable),
295
+ " UPDATE %s SET str_field = $1 where str_field = $2 RETURNING *" .format(BaseIntegrationSpec .pgTestTable),
299
296
Param (" hello_updated" ),
300
297
Param (" xxxx" )
301
298
)(identity)
@@ -312,7 +309,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
312
309
insertSampleData(client)
313
310
314
311
val preparedQuery = client.prepareAndQuery(
315
- " DELETE FROM %s WHERE str_field=$1" .format(IntegrationSpec .pgTestTable),
312
+ " DELETE FROM %s WHERE str_field=$1" .format(BaseIntegrationSpec .pgTestTable),
316
313
Param (" xxxx" )
317
314
)(identity)
318
315
@@ -347,7 +344,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
347
344
cleanDb(client)
348
345
349
346
val selectQuery = client.select(
350
- " SELECT * FROM %s WHERE unknown_column='hello_updated'" .format(IntegrationSpec .pgTestTable)
347
+ " SELECT * FROM %s WHERE unknown_column='hello_updated'" .format(BaseIntegrationSpec .pgTestTable)
351
348
)(identity)
352
349
353
350
a[ServerError ] must be thrownBy {
@@ -368,7 +365,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
368
365
cleanDb(client)
369
366
370
367
val preparedQuery = client.prepareAndQuery(
371
- " SELECT * FROM %s WHERE str_field=$1 AND bool_field=$2" .format(IntegrationSpec .pgTestTable),
368
+ " SELECT * FROM %s WHERE str_field=$1 AND bool_field=$2" .format(BaseIntegrationSpec .pgTestTable),
372
369
Param (" hello" )
373
370
)(identity)
374
371
0 commit comments