Elffuss BraidHub

kikocis/java-driver public

Added more tests for conditional queries (JAVA-358)
Changeset1e2046bae562324aebe07316bd4abda3264edd46d93a6740437b8f74c71d2855
AuthorPierre Laporte <pierre@pingtimeout.fr> · 2014-09-08 16:52 -07:00
CommitterPierre Laporte <pierre@pingtimeout.fr> · 2014-09-08 16:54 -07:00
Parents0385b2721a89

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/ConditionalUpdateTest.java +45 −0
@@ -64,4 +64,49 @@
6464
6565 assertTrue(rs.wasApplied());
6666 }
67+
68+ /**
69+ * Test for #JAVA-358 - Directly expose CAS_RESULT_COLUMN.
70+ * <p/>
71+ * This test makes sure that the boolean flag {@code ResultSet.wasApplied()} is false when we try to insert a row
72+ * which already exists.
73+ *
74+ * @see ResultSet#wasApplied()
75+ */
76+ @Test(groups = "short")
77+ public void insert_if_not_exist_should_support_wasApplied_boolean() {
78+ // First, make sure the test table and the row exist
79+ session.execute("CREATE TABLE IF NOT EXISTS Java358 (key int primary key, value int)");
80+ ResultSet rs;
81+ rs = session.execute("INSERT INTO Java358(key, value) VALUES (42, 42) IF NOT EXISTS");
82+ assertTrue(rs.wasApplied());
83+
84+ // Then, make sure the flag reports correctly that we did not create a new row
85+ rs = session.execute("INSERT INTO Java358(key, value) VALUES (42, 42) IF NOT EXISTS");
86+ assertFalse(rs.wasApplied());
87+ }
88+
89+ /**
90+ * Test for #JAVA-358 - Directly expose CAS_RESULT_COLUMN.
91+ * <p/>
92+ * This test makes sure that the boolean flag {@code ResultSet.wasApplied()} is false when we try to delete a row
93+ * which does not exist.
94+ *
95+ * @see ResultSet#wasApplied()
96+ */
97+ @Test(groups = "short")
98+ public void delete_if_not_exist_should_support_wasApplied_boolean() {
99+ // First, make sure the test table and the row exist
100+ session.execute("CREATE TABLE IF NOT EXISTS Java358 (key int primary key, value int)");
101+ session.execute("INSERT INTO Java358(key, value) VALUES (42, 42)");
102+
103+ // Then, make sure the flag reports correctly that we did delete the row
104+ ResultSet rs;
105+ rs = session.execute("DELETE FROM Java358 WHERE KEY=42 IF EXISTS");
106+ assertTrue(rs.wasApplied());
107+
108+ // Finally, make sure the flag reports correctly that we did did not delete an non-existing row
109+ rs = session.execute("DELETE FROM Java358 WHERE KEY=42 IF EXISTS");
110+ assertFalse(rs.wasApplied());
111+ }
67112 }