kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 187503b761be1900637a69a6e5ed86115d7a21d5f287da1b8a73282359c4da12 |
|---|---|
| Author | Ranger Tsao <cao.zhifu@gmail.com> · 2015-08-04 13:32 -05:00 |
| Committer | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-08-04 13:34 -05:00 |
| Parents | 09d548c3199c |
2 files changed
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderITest.java +35 −5
| @@ -72,8 +72,6 @@ | ||
| 72 | 72 | |
| 73 | 73 | query = "SELECT * FROM foo WHERE k=?;"; |
| 74 | 74 | select = select().all().from("foo").where(eq("k", QueryBuilder.bindMarker())); |
| 75 | - System.out.println(select.toString()); | |
| 76 | - System.out.println(session); | |
| 77 | 75 | ps = session.prepare(select.toString()); |
| 78 | 76 | bs = ps.bind(); |
| 79 | 77 | assertEquals(select.toString(), query); |
| @@ -211,13 +209,13 @@ | ||
| 211 | 209 | @CassandraVersion(major=2.0, minor=7, description="DELETE..IF EXISTS only supported in 2.0.7+ (CASSANDRA-5708)") |
| 212 | 210 | public void conditionalDeletesTest() throws Exception { |
| 213 | 211 | session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)",keyspace)); |
| 214 | - | |
| 212 | + | |
| 215 | 213 | Statement delete; |
| 216 | 214 | Row row; |
| 217 | 215 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 2)).ifExists(); |
| 218 | 216 | row = session.execute(delete).one(); |
| 219 | 217 | assertFalse(row.getBool("[applied]")); |
| 220 | - | |
| 218 | + | |
| 221 | 219 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).ifExists(); |
| 222 | 220 | row = session.execute(delete).one(); |
| 223 | 221 | assertTrue(row.getBool("[applied]")); |
| @@ -227,9 +225,41 @@ | ||
| 227 | 225 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 2)); |
| 228 | 226 | row = session.execute(delete).one(); |
| 229 | 227 | assertFalse(row.getBool("[applied]")); |
| 230 | - | |
| 228 | + | |
| 231 | 229 | delete = delete().from(keyspace, TABLE_INT).where(eq("k", 1)).onlyIf(eq("a", 1)).and(eq("b", 1)); |
| 232 | 230 | row = session.execute(delete).one(); |
| 233 | 231 | assertTrue(row.getBool("[applied]")); |
| 234 | 232 | } |
| 233 | + | |
| 234 | + @Test(groups = "short") | |
| 235 | + @CassandraVersion(major=2.0, minor=13, description="Allow IF EXISTS for UPDATE statements (CASSANDRA-8610)") | |
| 236 | + public void conditionalUpdatesTest() throws Exception { | |
| 237 | + session.execute(String.format("INSERT INTO %s.test_int (k, a, b) VALUES (1, 1, 1)",keyspace)); | |
| 238 | + | |
| 239 | + Statement update; | |
| 240 | + Row row; | |
| 241 | + update = update(TABLE_INT).with(set("a", 2)).and(set("b", 2)).where(eq("k", 2)).ifExists(); | |
| 242 | + row = session.execute(update).one(); | |
| 243 | + assertFalse(row.getBool("[applied]")); | |
| 244 | + | |
| 245 | + update = update(TABLE_INT).with(set("a", 2)).and(set("b", 2)).where(eq("k", 1)).ifExists(); | |
| 246 | + row = session.execute(update).one(); | |
| 247 | + assertTrue(row.getBool("[applied]")); | |
| 248 | + | |
| 249 | + update = update(TABLE_INT).with(set("a", 2)).and(set("b", 2)).where(eq("k", 2)).onlyIf(eq("a", 1)).and(eq("b", 2)); | |
| 250 | + row = session.execute(update).one(); | |
| 251 | + assertFalse(row.getBool("[applied]")); | |
| 252 | + | |
| 253 | + update = update(TABLE_INT).with(set("a", 3)).and(set("b", 3)).where(eq("k", 1)).onlyIf(eq("a", 2)).and(eq("b", 2)); | |
| 254 | + row = session.execute(update).one(); | |
| 255 | + assertTrue(row.getBool("[applied]")); | |
| 256 | + | |
| 257 | + update = update(TABLE_INT).with(set("a", 4)).and(set("b", 4)).onlyIf(eq("a", 2)).and(eq("b", 2)).where(eq("k", 1)); | |
| 258 | + row = session.execute(update).one(); | |
| 259 | + assertFalse(row.getBool("[applied]")); | |
| 260 | + | |
| 261 | + update = update(TABLE_INT).with(set("a", 4)).and(set("b", 4)).onlyIf(eq("a", 3)).and(eq("b", 3)).where(eq("k", 1)); | |
| 262 | + row = session.execute(update).one(); | |
| 263 | + assertTrue(row.getBool("[applied]")); | |
| 264 | + } | |
| 235 | 265 | } |
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java +4 −5
| @@ -285,7 +285,7 @@ | ||
| 285 | 285 | assertEquals(update.toString(), query); |
| 286 | 286 | |
| 287 | 287 | try { |
| 288 | - update = update("foo").using(ttl(-400)); | |
| 288 | + update("foo").using(ttl(-400)); | |
| 289 | 289 | fail(); |
| 290 | 290 | } catch (IllegalArgumentException e) { |
| 291 | 291 | assertEquals(e.getMessage(), "Invalid ttl, must be positive"); |
| @@ -295,10 +295,9 @@ | ||
| 295 | 295 | query = "UPDATE foo SET x=4 WHERE k=0 IF x=1;"; |
| 296 | 296 | update = update("foo").with(set("x", 4)).where(eq("k", 0)).onlyIf(eq("x", 1)); |
| 297 | 297 | assertEquals(update.toString(), query); |
| 298 | - } | |
| 299 | - @Test(groups = "unit") | |
| 300 | - public void should_handle_update_with_conditions_and_if_exists() { | |
| 301 | - Statement update = update("foo").with(set("x", 3)).where(eq("k", 2)).ifExists(); | |
| 298 | + | |
| 299 | + // IF EXISTS CAS test | |
| 300 | + update = update("foo").with(set("x", 3)).where(eq("k", 2)).ifExists(); | |
| 302 | 301 | assertThat(update.toString()).isEqualTo("UPDATE foo SET x=3 WHERE k=2 IF EXISTS;"); |
| 303 | 302 | } |
| 304 | 303 |