kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 44f554ac75548dd8a187c2ef7836f240e5361d2c4029775c1992a956ca178938 |
|---|---|
| Author | Gianluca Righetto <gianluca@menttis.com> · 2015-05-06 00:18 -03:00 |
| Committer | Gianluca Righetto <gianluca@menttis.com> · 2015-05-06 00:18 -03:00 |
| Parents | 62321c99b59c |
4 files changed
modified driver-core/src/test/java/com/datastax/driver/core/Assertions.java +6 −0
| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | package com.datastax.driver.core; |
| 2 | 2 | |
| 3 | +import com.datastax.driver.core.ColumnMetadata.IndexMetadata; | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * Augment AssertJ with custom assertions for the Java driver. |
| 5 | 7 | */ |
| @@ -19,4 +21,8 @@ | ||
| 19 | 21 | public static DataTypeAssert assertThat(DataType type) { |
| 20 | 22 | return new DataTypeAssert(type); |
| 21 | 23 | } |
| 24 | + | |
| 25 | + public static IndexMetadataAssert assertThat(IndexMetadata indexMetadata) { | |
| 26 | + return new IndexMetadataAssert(indexMetadata); | |
| 27 | + } | |
| 22 | 28 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +2 −0
| @@ -453,6 +453,8 @@ | ||
| 453 | 453 | |
| 454 | 454 | protected static Cluster cluster; |
| 455 | 455 | protected static Session session; |
| 456 | + | |
| 457 | + protected final VersionNumber cassandraVersion = VersionNumber.parse(System.getProperty("cassandra.version")); | |
| 456 | 458 | |
| 457 | 459 | protected abstract Collection<String> getTableDefinitions(); |
| 458 | 460 |
added driver-core/src/test/java/com/datastax/driver/core/IndexMetadataAssert.java +70 −0
| @@ -0,0 +1,70 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 4 | + | |
| 5 | +import org.assertj.core.api.AbstractAssert; | |
| 6 | + | |
| 7 | +import com.datastax.driver.core.ColumnMetadata.IndexMetadata; | |
| 8 | + | |
| 9 | +public class IndexMetadataAssert extends AbstractAssert<IndexMetadataAssert, IndexMetadata> { | |
| 10 | + | |
| 11 | + public IndexMetadataAssert(IndexMetadata actual) { | |
| 12 | + super(actual, IndexMetadataAssert.class); | |
| 13 | + } | |
| 14 | + | |
| 15 | + public IndexMetadataAssert hasName(String name) { | |
| 16 | + assertThat(actual.getName()).isEqualTo(name); | |
| 17 | + return this; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public IndexMetadataAssert hasOption(String name, String value) { | |
| 21 | + assertThat(actual.getOption(name)).isEqualTo(value); | |
| 22 | + return this; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public IndexMetadataAssert asCqlQuery(String cqlQuery) { | |
| 26 | + assertThat(actual.asCQLQuery()).isEqualTo(cqlQuery); | |
| 27 | + return this; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public IndexMetadataAssert isKeys(){ | |
| 31 | + assertThat(actual.isKeys()).isTrue(); | |
| 32 | + return this; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public IndexMetadataAssert isNotKeys(){ | |
| 36 | + assertThat(actual.isKeys()).isFalse(); | |
| 37 | + return this; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public IndexMetadataAssert isFull() { | |
| 41 | + assertThat(actual.isFull()).isTrue(); | |
| 42 | + return this; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public IndexMetadataAssert isNotFull() { | |
| 46 | + assertThat(actual.isFull()).isFalse(); | |
| 47 | + return this; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public IndexMetadataAssert isEntries() { | |
| 51 | + assertThat(actual.isEntries()).isTrue(); | |
| 52 | + return this; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public IndexMetadataAssert isNotEntries() { | |
| 56 | + assertThat(actual.isEntries()).isFalse(); | |
| 57 | + return this; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public IndexMetadataAssert isCustomIndex() { | |
| 61 | + assertThat(actual.isCustomIndex()).isTrue(); | |
| 62 | + return this; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public IndexMetadataAssert isNotCustomIndex() { | |
| 66 | + assertThat(actual.isCustomIndex()).isFalse(); | |
| 67 | + return this; | |
| 68 | + } | |
| 69 | + | |
| 70 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/IndexMetadataTest.java +75 −50
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | package com.datastax.driver.core; |
| 2 | 2 | |
| 3 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 3 | 4 | import static com.datastax.driver.core.ColumnMetadata.COLUMN_NAME; |
| 4 | 5 | import static com.datastax.driver.core.ColumnMetadata.COMPONENT_INDEX; |
| 5 | 6 | import static com.datastax.driver.core.ColumnMetadata.INDEX_NAME; |
| @@ -14,7 +15,6 @@ | ||
| 14 | 15 | import java.util.Collection; |
| 15 | 16 | import java.util.List; |
| 16 | 17 | |
| 17 | -import org.testng.Assert; | |
| 18 | 18 | import org.testng.annotations.Test; |
| 19 | 19 | |
| 20 | 20 | import com.datastax.driver.core.ColumnMetadata.IndexMetadata; |
| @@ -25,7 +25,7 @@ | ||
| 25 | 25 | import com.google.common.primitives.Ints; |
| 26 | 26 | |
| 27 | 27 | @CassandraVersion( |
| 28 | - major = 2.1) | |
| 28 | + major = 1.2) | |
| 29 | 29 | public class IndexMetadataTest extends CCMBridge.PerClassSingleNodeCluster { |
| 30 | 30 | |
| 31 | 31 | @Override |
| @@ -35,39 +35,63 @@ | ||
| 35 | 35 | + "map_values map<text, int>," |
| 36 | 36 | + "map_keys map<text, int>," |
| 37 | 37 | + "map_entries map<text, int>," |
| 38 | - + "map_full frozen<map<text, int>>," | |
| 39 | - + "set_full frozen<set<text>>," | |
| 40 | - + "list_full frozen<list<text>>," | |
| 41 | - + "custom text)"; | |
| 38 | + + "text_column text" | |
| 39 | + + | |
| 40 | + // Frozen collections was introduced only in C* 2.1.3 | |
| 41 | + (cassandraVersion.compareTo(VersionNumber.parse("2.1.3")) >= 0 | |
| 42 | + ? | |
| 43 | + ", map_full frozen<map<text, int>>," | |
| 44 | + + "set_full frozen<set<text>>," | |
| 45 | + + "list_full frozen<list<text>>);" | |
| 46 | + : | |
| 47 | + ")"); | |
| 42 | 48 | return ImmutableList.of(createTable); |
| 43 | 49 | } |
| 50 | + | |
| 51 | + @Test( | |
| 52 | + groups = "short") | |
| 53 | + public void should_not_flag_text_column_index_type() { | |
| 54 | + String createValuesIndex = String.format("CREATE INDEX text_column_index ON %s.indexing (text_column);", keyspace); | |
| 55 | + session.execute(createValuesIndex); | |
| 56 | + IndexMetadata index = getIndexForColumn("text_column"); | |
| 57 | + assertThat(index).hasName("text_column_index") | |
| 58 | + .isNotKeys() | |
| 59 | + .isNotFull() | |
| 60 | + .isNotEntries() | |
| 61 | + .isNotCustomIndex() | |
| 62 | + .asCqlQuery(createValuesIndex); | |
| 63 | + } | |
| 44 | 64 | |
| 45 | 65 | @Test( |
| 46 | 66 | groups = "short") |
| 67 | + @CassandraVersion( | |
| 68 | + major = 2.1) | |
| 47 | 69 | public void should_not_flag_map_index_type() { |
| 48 | 70 | String createValuesIndex = String.format("CREATE INDEX map_values_index ON %s.indexing (map_values);", keyspace); |
| 49 | 71 | session.execute(createValuesIndex); |
| 50 | 72 | IndexMetadata index = getIndexForColumn("map_values"); |
| 51 | - Assert.assertEquals(index.getName(), "map_values_index"); | |
| 52 | - Assert.assertFalse(index.isKeys()); | |
| 53 | - Assert.assertFalse(index.isFull()); | |
| 54 | - Assert.assertFalse(index.isEntries()); | |
| 55 | - Assert.assertFalse(index.isCustomIndex()); | |
| 56 | - Assert.assertEquals(index.asCQLQuery(), createValuesIndex); | |
| 73 | + assertThat(index).hasName("map_values_index") | |
| 74 | + .isNotKeys() | |
| 75 | + .isNotFull() | |
| 76 | + .isNotEntries() | |
| 77 | + .isNotCustomIndex() | |
| 78 | + .asCqlQuery(createValuesIndex); | |
| 57 | 79 | } |
| 58 | 80 | |
| 59 | 81 | @Test( |
| 60 | 82 | groups = "short") |
| 83 | + @CassandraVersion( | |
| 84 | + major = 2.1) | |
| 61 | 85 | public void should_flag_map_index_type_as_keys() { |
| 62 | 86 | String createKeysIndex = String.format("CREATE INDEX map_keys_index ON %s.indexing (KEYS(map_keys));", keyspace); |
| 63 | 87 | session.execute(createKeysIndex); |
| 64 | 88 | IndexMetadata index = getIndexForColumn("map_keys"); |
| 65 | - Assert.assertEquals(index.getName(), "map_keys_index"); | |
| 66 | - Assert.assertTrue(index.isKeys()); | |
| 67 | - Assert.assertFalse(index.isFull()); | |
| 68 | - Assert.assertFalse(index.isEntries()); | |
| 69 | - Assert.assertFalse(index.isCustomIndex()); | |
| 70 | - Assert.assertEquals(index.asCQLQuery(), createKeysIndex); | |
| 89 | + assertThat(index).hasName("map_keys_index") | |
| 90 | + .isKeys() | |
| 91 | + .isNotFull() | |
| 92 | + .isNotEntries() | |
| 93 | + .isNotCustomIndex() | |
| 94 | + .asCqlQuery(createKeysIndex); | |
| 71 | 95 | } |
| 72 | 96 | |
| 73 | 97 | @Test( |
| @@ -79,12 +103,12 @@ | ||
| 79 | 103 | String createFullIndex = String.format("CREATE INDEX map_full_index ON %s.indexing (FULL(map_full));", keyspace); |
| 80 | 104 | session.execute(createFullIndex); |
| 81 | 105 | IndexMetadata index = getIndexForColumn("map_full"); |
| 82 | - Assert.assertEquals(index.getName(), "map_full_index"); | |
| 83 | - Assert.assertFalse(index.isKeys()); | |
| 84 | - Assert.assertTrue(index.isFull()); | |
| 85 | - Assert.assertFalse(index.isEntries()); | |
| 86 | - Assert.assertFalse(index.isCustomIndex()); | |
| 87 | - Assert.assertEquals(index.asCQLQuery(), createFullIndex); | |
| 106 | + assertThat(index).hasName("map_full_index") | |
| 107 | + .isNotKeys() | |
| 108 | + .isFull() | |
| 109 | + .isNotEntries() | |
| 110 | + .isNotCustomIndex() | |
| 111 | + .asCqlQuery(createFullIndex); | |
| 88 | 112 | } |
| 89 | 113 | |
| 90 | 114 | @Test( |
| @@ -96,12 +120,12 @@ | ||
| 96 | 120 | String createFullIndex = String.format("CREATE INDEX set_full_index ON %s.indexing (FULL(set_full));", keyspace); |
| 97 | 121 | session.execute(createFullIndex); |
| 98 | 122 | IndexMetadata index = getIndexForColumn("set_full"); |
| 99 | - Assert.assertEquals(index.getName(), "set_full_index"); | |
| 100 | - Assert.assertFalse(index.isKeys()); | |
| 101 | - Assert.assertTrue(index.isFull()); | |
| 102 | - Assert.assertFalse(index.isEntries()); | |
| 103 | - Assert.assertFalse(index.isCustomIndex()); | |
| 104 | - Assert.assertEquals(index.asCQLQuery(), createFullIndex); | |
| 123 | + assertThat(index).hasName("set_full_index") | |
| 124 | + .isNotKeys() | |
| 125 | + .isFull() | |
| 126 | + .isNotEntries() | |
| 127 | + .isNotCustomIndex() | |
| 128 | + .asCqlQuery(createFullIndex); | |
| 105 | 129 | } |
| 106 | 130 | |
| 107 | 131 | @Test( |
| @@ -113,12 +137,12 @@ | ||
| 113 | 137 | String createFullIndex = String.format("CREATE INDEX list_full_index ON %s.indexing (FULL(list_full));", keyspace); |
| 114 | 138 | session.execute(createFullIndex); |
| 115 | 139 | IndexMetadata index = getIndexForColumn("list_full"); |
| 116 | - Assert.assertEquals(index.getName(), "list_full_index"); | |
| 117 | - Assert.assertFalse(index.isKeys()); | |
| 118 | - Assert.assertTrue(index.isFull()); | |
| 119 | - Assert.assertFalse(index.isEntries()); | |
| 120 | - Assert.assertFalse(index.isCustomIndex()); | |
| 121 | - Assert.assertEquals(index.asCQLQuery(), createFullIndex); | |
| 140 | + assertThat(index).hasName("list_full_index") | |
| 141 | + .isNotKeys() | |
| 142 | + .isFull() | |
| 143 | + .isNotEntries() | |
| 144 | + .isNotCustomIndex() | |
| 145 | + .asCqlQuery(createFullIndex); | |
| 122 | 146 | } |
| 123 | 147 | |
| 124 | 148 | @Test( |
| @@ -129,12 +153,12 @@ | ||
| 129 | 153 | String createEntriesIndex = String.format("CREATE INDEX map_entries_index ON %s.indexing (ENTRIES(map_entries));", keyspace); |
| 130 | 154 | session.execute(createEntriesIndex); |
| 131 | 155 | IndexMetadata index = getIndexForColumn("map_entries"); |
| 132 | - Assert.assertEquals(index.getName(), "map_entries_index"); | |
| 133 | - Assert.assertFalse(index.isKeys()); | |
| 134 | - Assert.assertFalse(index.isFull()); | |
| 135 | - Assert.assertTrue(index.isEntries()); | |
| 136 | - Assert.assertFalse(index.isCustomIndex()); | |
| 137 | - Assert.assertEquals(index.asCQLQuery(), createEntriesIndex); | |
| 156 | + assertThat(index).hasName("map_entries_index") | |
| 157 | + .isNotKeys() | |
| 158 | + .isNotFull() | |
| 159 | + .isEntries() | |
| 160 | + .isNotCustomIndex() | |
| 161 | + .asCqlQuery(createEntriesIndex); | |
| 138 | 162 | } |
| 139 | 163 | |
| 140 | 164 | @Test( |
| @@ -153,7 +177,7 @@ | ||
| 153 | 177 | definition(INDEX_OPTIONS, text()) |
| 154 | 178 | }); |
| 155 | 179 | List<ByteBuffer> data = ImmutableList.of( |
| 156 | - wrap("custom"), // column name | |
| 180 | + wrap("text_column"), // column name | |
| 157 | 181 | wrap(0), // component index |
| 158 | 182 | wrap("regular"), // kind |
| 159 | 183 | wrap("custom_index"), // index name |
| @@ -164,13 +188,14 @@ | ||
| 164 | 188 | Row row = ArrayBackedRow.fromData(defs, M3PToken.FACTORY, ProtocolVersion.V3, data); |
| 165 | 189 | ColumnMetadata column = ColumnMetadata.fromRaw(table, Raw.fromRow(row, VersionNumber.parse("2.1"))); |
| 166 | 190 | IndexMetadata index = column.getIndex(); |
| 167 | - Assert.assertFalse(index.isKeys()); | |
| 168 | - Assert.assertFalse(index.isFull()); | |
| 169 | - Assert.assertFalse(index.isEntries()); | |
| 170 | - Assert.assertTrue(index.isCustomIndex()); | |
| 171 | - Assert.assertEquals(index.getOption("foo"), "bar"); | |
| 172 | - Assert.assertEquals(index.asCQLQuery(), "CREATE CUSTOM INDEX custom_index ON ks_1.indexing (custom) " | |
| 173 | - + "USING 'dummy.DummyIndex' WITH OPTIONS = {'foo' : 'bar', 'class_name' : 'dummy.DummyIndex'};"); | |
| 191 | + assertThat(index).hasName("custom_index") | |
| 192 | + .isNotKeys() | |
| 193 | + .isNotFull() | |
| 194 | + .isNotEntries() | |
| 195 | + .isCustomIndex() | |
| 196 | + .hasOption("foo", "bar") | |
| 197 | + .asCqlQuery("CREATE CUSTOM INDEX custom_index ON ks_1.indexing (text_column) " | |
| 198 | + + "USING 'dummy.DummyIndex' WITH OPTIONS = {'foo' : 'bar', 'class_name' : 'dummy.DummyIndex'};"); | |
| 174 | 199 | } |
| 175 | 200 | |
| 176 | 201 | private ColumnDefinitions.Definition definition(String name, DataType type) { |