16
16
17
17
package com .google .cloud .spanner .it ;
18
18
19
+ import static com .google .cloud .spanner .testing .EmulatorSpannerHelper .isUsingEmulator ;
20
+ import static com .google .common .base .Strings .isNullOrEmpty ;
19
21
import static com .google .common .truth .Truth .assertThat ;
20
22
import static org .junit .Assert .assertFalse ;
21
23
import static org .junit .Assert .assertNotNull ;
22
24
import static org .junit .Assert .assertTrue ;
23
25
import static org .junit .Assert .fail ;
26
+ import static org .junit .Assume .assumeFalse ;
24
27
import static org .junit .Assume .assumeTrue ;
25
28
26
29
import com .google .cloud .Timestamp ;
@@ -79,15 +82,15 @@ public static List<DialectTestParameter> data() {
79
82
+ " Key STRING(MAX) NOT NULL,"
80
83
+ " Float32Value FLOAT32,"
81
84
+ " Float32ArrayValue ARRAY<FLOAT32>,"
82
- + ") PRIMARY KEY (K )"
85
+ + ") PRIMARY KEY (Key )"
83
86
};
84
87
85
88
private static final String [] POSTGRESQL_SCHEMA =
86
89
new String [] {
87
90
"CREATE TABLE T ("
88
91
+ " Key VARCHAR PRIMARY KEY,"
89
92
+ " Float32Value REAL,"
90
- + " Float32ArrayValue REAL[], "
93
+ + " Float32ArrayValue REAL[]"
91
94
+ ")"
92
95
};
93
96
@@ -107,8 +110,18 @@ public static void setUpDatabase()
107
110
postgreSQLClient = env .getTestHelper ().getDatabaseClient (postgreSQLDatabase );
108
111
}
109
112
113
+ private static boolean isUsingCloudDevel () {
114
+ String jobType = System .getenv ("JOB_TYPE" );
115
+
116
+ // Assumes that the jobType contains the string "cloud-devel" to signal that
117
+ // the environment is cloud-devel.
118
+ return !isNullOrEmpty (jobType ) && jobType .contains ("cloud-devel" );
119
+ }
120
+
110
121
@ Before
111
122
public void before () {
123
+ assumeFalse ("Emulator does not support FLOAT32 yet" , isUsingEmulator ());
124
+
112
125
client =
113
126
dialect .dialect == Dialect .GOOGLE_STANDARD_SQL ? googleStandardSQLClient : postgreSQLClient ;
114
127
}
@@ -147,6 +160,8 @@ private Struct readLastRow(String... columns) {
147
160
148
161
@ Test
149
162
public void writeFloat32 () {
163
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
164
+
150
165
write (baseInsert ().set ("Float32Value" ).to (2.0f ).build ());
151
166
Struct row = readLastRow ("Float32Value" );
152
167
assertThat (row .isNull (0 )).isFalse ();
@@ -155,6 +170,8 @@ public void writeFloat32() {
155
170
156
171
@ Test
157
172
public void writeFloat32NonNumbers () {
173
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
174
+
158
175
write (baseInsert ().set ("Float32Value" ).to (Float .NEGATIVE_INFINITY ).build ());
159
176
Struct row = readLastRow ("Float32Value" );
160
177
assertThat (row .isNull (0 )).isFalse ();
@@ -173,20 +190,26 @@ public void writeFloat32NonNumbers() {
173
190
174
191
@ Test
175
192
public void writeFloat32Null () {
193
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
194
+
176
195
write (baseInsert ().set ("Float32Value" ).to ((Float ) null ).build ());
177
196
Struct row = readLastRow ("Float32Value" );
178
197
assertThat (row .isNull (0 )).isTrue ();
179
198
}
180
199
181
200
@ Test
182
201
public void writeFloat32ArrayNull () {
202
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
203
+
183
204
write (baseInsert ().set ("Float32ArrayValue" ).toFloat32Array ((float []) null ).build ());
184
205
Struct row = readLastRow ("Float32ArrayValue" );
185
206
assertThat (row .isNull (0 )).isTrue ();
186
207
}
187
208
188
209
@ Test
189
210
public void writeFloat32ArrayEmpty () {
211
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
212
+
190
213
write (baseInsert ().set ("Float32ArrayValue" ).toFloat32Array (new float [] {}).build ());
191
214
Struct row = readLastRow ("Float32ArrayValue" );
192
215
assertThat (row .isNull (0 )).isFalse ();
@@ -195,6 +218,8 @@ public void writeFloat32ArrayEmpty() {
195
218
196
219
@ Test
197
220
public void writeFloat32Array () {
221
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
222
+
198
223
write (
199
224
baseInsert ()
200
225
.set ("Float32ArrayValue" )
@@ -213,10 +238,12 @@ public void writeFloat32Array() {
213
238
214
239
@ Test
215
240
public void writeFloat32ArrayNoNulls () {
241
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
242
+
216
243
write (baseInsert ().set ("Float32ArrayValue" ).toFloat32Array (Arrays .asList (1.0f , 2.0f )).build ());
217
244
Struct row = readLastRow ("Float32ArrayValue" );
218
245
assertThat (row .isNull (0 )).isFalse ();
219
- assertThat (row .getFloatArray (0 ).length ).isEqualTo (2f );
246
+ assertThat (row .getFloatArray (0 ).length ).isEqualTo (2 );
220
247
assertThat (row .getFloatArray (0 )[0 ]).isWithin (0.0f ).of (1.0f );
221
248
assertThat (row .getFloatArray (0 )[1 ]).isWithin (0.0f ).of (2.0f );
222
249
}
@@ -244,6 +271,8 @@ private String getInsertStatementWithLiterals() {
244
271
245
272
@ Test
246
273
public void float32Literals () {
274
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
275
+
247
276
client
248
277
.readWriteTransaction ()
249
278
.run (
@@ -269,6 +298,8 @@ private String getInsertStatementWithParameters() {
269
298
270
299
@ Test
271
300
public void float32Parameter () {
301
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
302
+
272
303
client
273
304
.readWriteTransaction ()
274
305
.run (
@@ -311,9 +342,12 @@ public void float32Parameter() {
311
342
@ Ignore ("This will be supported before submission" )
312
343
@ Test
313
344
public void float32UntypedParameter () {
345
+ assumeTrue ("FLOAT32 is currently only supported in cloud-devel" , isUsingCloudDevel ());
346
+
314
347
// TODO: Verify before submitting.
315
348
assumeTrue (
316
- "This is only supported in GoogleSQL??" , dialect .dialect == Dialect .GOOGLE_STANDARD_SQL );
349
+ "This is currently only supported in GoogleSQL??" ,
350
+ dialect .dialect == Dialect .GOOGLE_STANDARD_SQL );
317
351
318
352
client
319
353
.readWriteTransaction ()
@@ -342,11 +376,13 @@ public void float32UntypedParameter() {
342
376
.build ());
343
377
return null ;
344
378
});
379
+
380
+ // TODO: add verifier.
345
381
}
346
382
347
383
private void verifyContents () {
348
384
try (ResultSet resultSet =
349
- client .singleUse ().executeQuery (Statement .of ("SELECT * FROM T ORDER BY id " ))) {
385
+ client .singleUse ().executeQuery (Statement .of ("SELECT * FROM T ORDER BY Key " ))) {
350
386
351
387
assertTrue (resultSet .next ());
352
388
0 commit comments