@@ -40,27 +40,9 @@ public class TestRediSearchConnectorSmokeTest extends BaseConnectorSmokeTest {
40
40
private RediSearchServer redisearch ;
41
41
42
42
private void populateBeers () throws IOException , InterruptedException {
43
- deleteBeers ();
44
43
Beers .populateIndex (redisearch .getTestContext ().getConnection ());
45
44
}
46
45
47
- private void createBeersIndex () throws InterruptedException {
48
- deleteBeers ();
49
- Beers .createIndex (redisearch .getTestContext ().getConnection ());
50
- }
51
-
52
- private void deleteBeers () throws InterruptedException {
53
- try {
54
- redisearch .getTestContext ().sync ().ftDropindexDeleteDocs (Beers .INDEX );
55
- } catch (Exception e ) {
56
- // ignore
57
- }
58
- long start = System .currentTimeMillis ();
59
- while (redisearch .getTestContext ().sync ().dbsize () > 0 && System .currentTimeMillis () < start + 3000 ) {
60
- Thread .sleep (10 );
61
- }
62
- }
63
-
64
46
@ Override
65
47
protected boolean hasBehavior (TestingConnectorBehavior connectorBehavior ) {
66
48
switch (connectorBehavior ) {
@@ -128,21 +110,19 @@ protected QueryRunner createQueryRunner() throws Exception {
128
110
}
129
111
130
112
@ Test
131
- public void testNonIndexedFields () throws IOException , InterruptedException {
113
+ public void testRediSearchFields () throws IOException , InterruptedException {
132
114
populateBeers ();
133
115
getQueryRunner ().execute ("select id, last_mod from beers" );
134
- }
135
-
136
- @ Test
137
- public void testBuiltinFields () throws IOException , InterruptedException {
138
- populateBeers ();
139
116
getQueryRunner ().execute ("select _id, _score from beers" );
140
117
}
141
118
119
+ @ SuppressWarnings ("unchecked" )
142
120
@ Test
143
121
public void testCountEmptyIndex () throws IOException , InterruptedException {
144
- createBeersIndex ();
145
- assertQuery ("SELECT count(*) FROM beers" , "VALUES 0" );
122
+ String index = "emptyidx" ;
123
+ CreateOptions <String , String > options = CreateOptions .<String , String >builder ().prefix (index + ":" ).build ();
124
+ redisearch .getTestContext ().sync ().ftCreate (index , options , Field .tag ("field1" ).build ());
125
+ assertQuery ("SELECT count(*) FROM " + index , "VALUES 0" );
146
126
}
147
127
148
128
@ SuppressWarnings ("unchecked" )
@@ -166,14 +146,19 @@ public void testShowCreateTable() {
166
146
throw new SkipException ("Not supported by RediSearch connector" );
167
147
}
168
148
149
+ @ SuppressWarnings ("unchecked" )
169
150
@ Test
170
151
public void testInsertIndex () throws IOException , InterruptedException {
171
- createBeersIndex ();
172
- assertUpdate ("INSERT INTO beers (id, name) VALUES ('abc', 'mybeer')" , 1 );
173
- assertThat (query ("SELECT id, name FROM beers" )).matches ("VALUES (VARCHAR 'abc', VARCHAR 'mybeer')" );
174
- List <String > keys = redisearch .getTestContext ().sync ().keys ("beer:*" );
152
+ String index = "insertidx" ;
153
+ String prefix = index + ":" ;
154
+ CreateOptions <String , String > options = CreateOptions .<String , String >builder ().prefix (prefix ).build ();
155
+ redisearch .getTestContext ().sync ().ftCreate (index , options , Field .tag ("id" ).build (), Field .tag ("name" ).build ());
156
+ assertUpdate (String .format ("INSERT INTO %s (id, name) VALUES ('abc', 'mybeer')" , index ), 1 );
157
+ assertThat (query (String .format ("SELECT id, name FROM %s" , index )))
158
+ .matches ("VALUES (VARCHAR 'abc', VARCHAR 'mybeer')" );
159
+ List <String > keys = redisearch .getTestContext ().sync ().keys (prefix + "*" );
175
160
assertEquals (keys .size (), 1 );
176
- assertTrue (keys .get (0 ).startsWith ("beer:" ));
161
+ assertTrue (keys .get (0 ).startsWith (prefix ));
177
162
}
178
163
179
164
@ AfterClass (alwaysRun = true )
0 commit comments