1- package com .twitter .finagle .postgres . integration
1+ package com .twitter .finagle .postgres
22
33import java .sql .Timestamp
44import java .time .Instant
55
6- import com .twitter .finagle .postgres . _
6+ import com .twitter .finagle .{ Postgres , Status }
77import 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 }
129
13- object IntegrationSpec {
10+ object BaseIntegrationSpec {
1411 val pgTestTable = " finagle_test"
1512}
1613
17- class IntegrationSpec extends EmbeddedPgSqlSpec {
14+ abstract class BaseIntegrationSpec ( version : String ) extends EmbeddedPgSqlSpec {
1815
1916 val queryTimeout = Duration .fromSeconds(2 )
2017
@@ -29,7 +26,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
2926 }
3027
3128 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))
3330 val response = Await .result(dropQuery, queryTimeout)
3431
3532 response must equal(OK (1 ))
@@ -43,7 +40,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
4340 | timestamp_field TIMESTAMP WITH TIME ZONE,
4441 | bool_field BOOLEAN
4542 |)
46- """ .stripMargin.format(IntegrationSpec .pgTestTable))
43+ """ .stripMargin.format(BaseIntegrationSpec .pgTestTable))
4744 val response2 = Await .result(createTableQuery, queryTimeout)
4845 response2 must equal(OK (1 ))
4946 }
@@ -56,21 +53,21 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
5653 | ('hello', 5557, -4.51, '2015-01-08 12:55:12-0800', TRUE),
5754 | ('hello', 7787, -42.51, '2013-12-24 07:01:00-0800', FALSE),
5855 | ('goodbye', 4567, 15.8, '2015-01-09 16:55:12+0500', FALSE)
59- """ .stripMargin.format(IntegrationSpec .pgTestTable))
56+ """ .stripMargin.format(BaseIntegrationSpec .pgTestTable))
6057
6158 val response = Await .result(insertDataQuery, queryTimeout)
6259
6360 response must equal(OK (4 ))
6461 }
6562
66- " A postgres client" should {
63+ s " A postgres client against Postgresql v $version " should {
6764 " insert and select rows" in {
6865 val client = getClient
6966 cleanDb(client)
7067 insertSampleData(client)
7168
7269 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)
7471 )(
7572 identity)
7673
@@ -103,7 +100,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
103100 " SELECT * FROM %s WHERE str_field='xxxx' ORDER BY timestamp_field" .
104101 format(
105102
106- IntegrationSpec .pgTestTable)
103+ BaseIntegrationSpec .pgTestTable)
107104 )(identity)
108105
109106 val
@@ -121,7 +118,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
121118
122119 val updateQuery = client.executeUpdate(
123120
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)
125122 )
126123
127124 val response = Await .
@@ -132,7 +129,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
132129
133130 val selectQuery = client.select(
134131
135- " SELECT * FROM %s WHERE str_field='hello_updated'" .format(IntegrationSpec .pgTestTable)
132+ " SELECT * FROM %s WHERE str_field='hello_updated'" .format(BaseIntegrationSpec .pgTestTable)
136133 )(
137134
138135 identity)
@@ -152,15 +149,15 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
152149
153150 val updateQuery = client.executeUpdate(
154151 " DELETE FROM %s WHERE str_field='hello'"
155- .format(IntegrationSpec .pgTestTable)
152+ .format(BaseIntegrationSpec .pgTestTable)
156153 )
157154
158155 val response = Await .result(updateQuery, queryTimeout)
159156
160157 response must equal(OK (3 ))
161158
162159 val selectQuery = client.select(
163- " SELECT * FROM %s" .format(IntegrationSpec .pgTestTable)
160+ " SELECT * FROM %s" .format(BaseIntegrationSpec .pgTestTable)
164161 )(identity)
165162
166163 val resultRows = Await .result(selectQuery, queryTimeout)
@@ -176,7 +173,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
176173 insertSampleData(client)
177174
178175 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),
180177 Param (" hello" ),
181178 Param (true ))(identity)
182179
@@ -199,14 +196,14 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
199196 insertSampleData(client)
200197
201198 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),
203200 Param (" hello_updated" )
204201 )
205202
206203 val numRows = Await .result(preparedQuery)
207204
208205 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)
210207 )(identity))
211208
212209 resultRows.size must equal(numRows)
@@ -219,14 +216,14 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
219216
220217
221218 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),
223220 Some (" hello_updated_some" )
224221 )
225222
226223 val numRows = Await .result(preparedQuery)
227224
228225 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)
230227 )(identity))
231228
232229 resultRows.size must equal(numRows)
@@ -239,14 +236,14 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
239236
240237
241238 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),
243240 None : Option [String ]
244241 )
245242
246243 val numRows = Await .result(preparedQuery)
247244
248245 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)
250247 )(identity))
251248
252249 resultRows.size must equal(numRows)
@@ -259,7 +256,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
259256
260257
261258 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),
263260 Param (" hello_updated" )
264261 )(identity)
265262
@@ -275,12 +272,12 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
275272 insertSampleData(client)
276273
277274 Await .result(client.prepareAndExecute(
278- s """ INSERT INTO ${IntegrationSpec .pgTestTable}
275+ s """ INSERT INTO ${BaseIntegrationSpec .pgTestTable}
279276 VALUES ('delete', 9012, 15.8, '2015-01-09 16:55:12+0500', FALSE) """
280277 ))
281278
282279 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)
284281 )(identity)
285282
286283 val resultRows = Await .result(preparedQuery)
@@ -295,7 +292,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
295292 cleanDb(client)
296293 insertSampleData(client)
297294 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),
299296 Param (" hello_updated" ),
300297 Param (" xxxx" )
301298 )(identity)
@@ -312,7 +309,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
312309 insertSampleData(client)
313310
314311 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),
316313 Param (" xxxx" )
317314 )(identity)
318315
@@ -347,7 +344,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
347344 cleanDb(client)
348345
349346 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)
351348 )(identity)
352349
353350 a[ServerError ] must be thrownBy {
@@ -368,7 +365,7 @@ class IntegrationSpec extends EmbeddedPgSqlSpec {
368365 cleanDb(client)
369366
370367 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),
372369 Param (" hello" )
373370 )(identity)
374371
0 commit comments