28
28
import java .net .InetAddress ;
29
29
import java .nio .ByteBuffer ;
30
30
import java .util .*;
31
+ import java .util .concurrent .Callable ;
31
32
33
+ import sta
10000
tic com .datastax .driver .core .ConditionChecker .check ;
32
34
import static com .datastax .driver .core .Metadata .quote ;
35
+ import static java .util .concurrent .TimeUnit .MINUTES ;
33
36
import static org .testng .Assert .assertEquals ;
34
37
import static org .testng .Assert .assertNotEquals ;
35
38
36
39
@ CassandraVersion (major = 2.1 )
37
40
public class UserTypesTest extends CCMTestsSupport {
38
41
39
42
private final static List <DataType > DATA_TYPE_PRIMITIVES = new ArrayList <DataType >(DataType .allPrimitiveTypes ());
43
+
44
+ static {
45
+ DATA_TYPE_PRIMITIVES .remove (DataType .counter ());
46
+ }
47
+
40
48
private final static List <DataType .Name > DATA_TYPE_NON_PRIMITIVE_NAMES =
41
49
new ArrayList <DataType .Name >(EnumSet .of (DataType .Name .LIST , DataType .Name .SET , DataType .Name .MAP , DataType .Name .TUPLE ));
42
50
51
+ private final Callable <Boolean > userTableExists = new Callable <Boolean >() {
52
+ @ Override
53
+ public Boolean call () throws Exception {
54
+ return cluster ().getMetadata ().getKeyspace (keyspace ).getTable ("user" ) != null ;
55
+ }
56
+ };
57
+
43
58
@ Override
44
59
public void onTestContextInitialized () {
45
60
String type1 = "CREATE TYPE phone (alias text, number text)" ;
46
- String type2 = "CREATE TYPE address (street text, \" ZIP\" int, phones set<frozen<phone>>)" ;
47
- String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<address >)" ;
61
+ String type2 = "CREATE TYPE \" \" \" User Address \" \" \" (street text, \" ZIP\" \" \" int, phones set<frozen<phone>>)" ;
62
+ String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<\" \" \" User Address \" \" \" >)" ;
48
63
execute (type1 , type2 , table );
64
+ // Ci tests fail with "unconfigured columnfamily user"
65
+ check ().that (userTableExists ).before (5 , MINUTES ).becomesTrue ();
49
66
}
50
67
51
68
/**
@@ -59,13 +76,13 @@ public void simpleWriteReadTest() throws Exception {
59
76
PreparedStatement ins = session ().prepare ("INSERT INTO user(id, addr) VALUES (?, ?)" );
60
77
PreparedStatement sel = session ().prepare ("SELECT * FROM user WHERE id=?" );
61
78
62
- UserType addrDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType ("address" );
79
+ UserType addrDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType (quote ( " \" User Address \" " ) );
63
80
UserType phoneDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType ("phone" );
64
81
65
82
UDTValue phone1 = phoneDef .newValue ().setString ("alias" , "home" ).setString ("number" , "0123548790" );
66
83
UDTValue phone2 = phoneDef .newValue ().setString ("alias" , "work" ).setString ("number" , "0698265251" );
67
84
68
- UDTValue addr = addrDef .newValue ().setString ("street" , "1600 Pennsylvania Ave NW" ).setInt (quote ("ZIP" ), 20500 ).setSet ("phones" , ImmutableSet .of (phone1 , phone2 ));
85
+ UDTValue addr = addrDef .newValue ().setString ("street" , "1600 Pennsylvania Ave NW" ).setInt (quote ("ZIP\" " ), 20500 ).setSet ("phones" , ImmutableSet .of (phone1 , phone2 ));
69
86
70
87
session ().execute (ins .bind (userId , addr ));
71
88
@@ -83,13 +100,14 @@ public void simpleWriteReadTest() throws Exception {
83
100
@ Test (groups = "short" )
84
101
public void simpleUnpreparedWriteReadTest () throws Exception {
85
102
int userId = 1 ;
86
- UserType addrDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType ("address" );
103
+ session ().execute ("USE " + keyspace );
104
+ UserType addrDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType (quote ("\" User Address\" " ));
87
105
UserType phoneDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType ("phone" );
88
106
89
107
UDTValue phone1 = phoneDef .newValue ().setString ("alias" , "home" ).setString ("number" , "0123548790" );
90
108
UDTValue phone2 = phoneDef .newValue ().setString ("alias" , "work" ).setString ("number" , "0698265251" );
91
109
92
- UDTValue addr = addrDef .newValue ().setString ("street" , "1600 Pennsylvania Ave NW" ).setInt (quote ("ZIP" ), 20500 ).setSet ("phones" , ImmutableSet .of (phone1 , phone2 ));
110
+ UDTValue addr = addrDef .newValue ().setString ("street" , "1600 Pennsylvania Ave NW" ).setInt (quote ("ZIP\" " ), 20500 ).setSet ("phones" , ImmutableSet .of (phone1 , phone2 ));
93
111
94
112
session ().execute ("INSERT INTO user(id, addr) VALUES (?, ?)" , userId , addr );
95
113
@@ -111,7 +129,7 @@ public void nonExistingTypesTest() throws Exception {
111
129
assertEquals (addrDef , null );
112
130
assertEquals (phoneDef , null );
113
131
114
- addrDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType ("address" );
132
+ addrDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType (quote ( " \" User Address \" " ) );
115
133
phoneDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType ("phone" );
116
134
assertNotEquals (addrDef , null );
117
135
assertNotEquals (phoneDef , null );
@@ -122,14 +140,14 @@ public void nonExistingTypesTest() throws Exception {
122
140
"WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}" );
123
141
session ().execute ("USE " + nonExistingKeyspace );
124
142
125
- addrDef = cluster ().getMetadata ().getKeyspace (nonExistingKeyspace ).getUserType ("address" );
143
+ addrDef = cluster ().getMetadata ().getKeyspace (nonExistingKeyspace ).getUserType (quote ( " \" User Address \" " ) );
126
144
phoneDef = cluster ().getMetadata ().getKeyspace (nonExistingKeyspace ).getUserType ("phone" );
127
145
assertEquals (addrDef , null );
128
146
assertEquals (phoneDef , null );
129
147
130
148
session ().execute ("USE " + keyspace );
131
149
132
- addrDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType ("address" );
150
+ addrDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType (quote ( " \" User Address \" " ) );
133
151
phoneDef = cluster ().getMetadata ().getKeyspace (keyspace ).getUserType ("phone" );
134
152
assertNotEquals (addrDef , null );
135
153
assertNotEquals (phoneDef , null );
0 commit comments