Skip to content

Commit d9205e7

Browse files
author
Julien Ruaux
committed
test: using different indexes for tests
1 parent 4ce6347 commit d9205e7

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

src/test/java/com/redis/trino/TestRediSearchConnectorSmokeTest.java

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,9 @@ public class TestRediSearchConnectorSmokeTest extends BaseConnectorSmokeTest {
4040
private RediSearchServer redisearch;
4141

4242
private void populateBeers() throws IOException, InterruptedException {
43-
deleteBeers();
4443
Beers.populateIndex(redisearch.getTestContext().getConnection());
4544
}
4645

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-
6446
@Override
6547
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior) {
6648
switch (connectorBehavior) {
@@ -128,21 +110,19 @@ protected QueryRunner createQueryRunner() throws Exception {
128110
}
129111

130112
@Test
131-
public void testNonIndexedFields() throws IOException, InterruptedException {
113+
public void testRediSearchFields() throws IOException, InterruptedException {
132114
populateBeers();
133115
getQueryRunner().execute("select id, last_mod from beers");
134-
}
135-
136-
@Test
137-
public void testBuiltinFields() throws IOException, InterruptedException {
138-
populateBeers();
139116
getQueryRunner().execute("select _id, _score from beers");
140117
}
141118

119+
@SuppressWarnings("unchecked")
142120
@Test
143121
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");
146126
}
147127

148128
@SuppressWarnings("unchecked")
@@ -166,14 +146,19 @@ public void testShowCreateTable() {
166146
throw new SkipException("Not supported by RediSearch connector");
167147
}
168148

149+
@SuppressWarnings("unchecked")
169150
@Test
170151
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 + "*");
175160
assertEquals(keys.size(), 1);
176-
assertTrue(keys.get(0).startsWith("beer:"));
161+
assertTrue(keys.get(0).startsWith(prefix));
177162
}
178163

179164
@AfterClass(alwaysRun = true)

0 commit comments

Comments
 (0)