Skip to content

Commit

Permalink
Avoid running redundant tests (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Jun 24, 2021
1 parent 6782280 commit 1ab1dcb
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 122 deletions.
44 changes: 28 additions & 16 deletions src/test/java/io/redisearch/client/AggregationBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,28 @@
import io.redisearch.aggregation.reducers.Reducers;
import redis.clients.jedis.exceptions.JedisDataException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import static junit.framework.TestCase.*;

import java.util.HashMap;
import java.util.Map;

/**
* Created by mnunberg on 5/17/18.
*/
public class AggregationBuilderTest extends ClientTest {
import static org.junit.Assert.*;

public class AggregationBuilderTest extends TestBase {

@BeforeClass
public static void prepare() {
TEST_INDEX = "aggregation-builder";
TestBase.prepare();
}

@AfterClass
public static void tearDown() {
TestBase.tearDown();
}

@Test
public void testAggregations() {
/**
Expand All @@ -32,7 +43,7 @@ public void testAggregations() {
127.0.0.1:6379> FT.ADD test_index data3 1.0 FIELDS name def count 25
*/

Client cl = getClient();
Client cl = getDefaultClient();
Schema sc = new Schema();
sc.addSortableTextField("name", 1.0);
sc.addSortableNumericField("count");
Expand All @@ -54,11 +65,11 @@ public void testAggregations() {
assertNotNull(r1);
assertEquals("def", r1.getString("name"));
assertEquals(30, r1.getLong("sum"));
assertEquals(30., r1.getDouble("sum"));
assertEquals(30., r1.getDouble("sum"), 0);


assertEquals(0L, r1.getLong("nosuchcol"));
assertEquals(0.0, r1.getDouble("nosuchcol"));
assertEquals(0.0, r1.getDouble("nosuchcol"), 0);
assertEquals("", r1.getString("nosuchcol"));


Expand Down Expand Up @@ -87,7 +98,7 @@ public void testApplyAndFilterAggregations() {
OK
*/

Client cl = getClient();
Client cl = getDefaultClient();
Schema sc = new Schema();
sc.addSortableTextField("name", 1.0);
sc.addSortableNumericField("subj1");
Expand All @@ -113,14 +124,15 @@ public void testApplyAndFilterAggregations() {
Row r1 = res.getRow(0);
assertNotNull(r1);
assertEquals("def", r1.getString("name"));
assertEquals(52.5, r1.getDouble("avgscore"));
assertEquals(52.5, r1.getDouble("avgscore"), 0);


Row r2 = res.getRow(1);
assertNotNull(r2);
assertEquals("ghi", r2.getString("name"));
assertEquals(67.5, r2.getDouble("avgscore"));
assertEquals(67.5, r2.getDouble("avgscore"), 0);
}

@Test
public void testCursor() throws InterruptedException {
/**
Expand All @@ -133,7 +145,7 @@ public void testCursor() throws InterruptedException {
127.0.0.1:6379> FT.ADD test_index data3 1.0 FIELDS name def count 25
*/

Client cl = getClient();
Client cl = getDefaultClient();
Schema sc = new Schema();
sc.addSortableTextField("name", 1.0);
sc.addSortableNumericField("count");
Expand All @@ -155,10 +167,10 @@ public void testCursor() throws InterruptedException {
assertNotNull(row);
assertEquals("def", row.getString("name"));
assertEquals(30, row.getLong("sum"));
assertEquals(30., row.getDouble("sum"));
assertEquals(30., row.getDouble("sum"), 0);

assertEquals(0L, row.getLong("nosuchcol"));
assertEquals(0.0, row.getDouble("nosuchcol"));
assertEquals(0.0, row.getDouble("nosuchcol"), 0);
assertEquals("", row.getString("nosuchcol"));

res = cl.cursorRead(res.getCursorId(), 1);
Expand Down Expand Up @@ -190,7 +202,7 @@ public void testCursor() throws InterruptedException {
@Test
public void testWrongAggregation() throws InterruptedException {

Client cl = getClient();
Client cl = getDefaultClient();
Schema sc = new Schema()
.addTextField("title", 5.0)
.addTextField("body", 1.0)
Expand Down
27 changes: 19 additions & 8 deletions src/test/java/io/redisearch/client/AggregationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@
import io.redisearch.aggregation.reducers.Reducers;
import redis.clients.jedis.exceptions.JedisDataException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by mnunberg on 5/17/18.
*/
@SuppressWarnings("deprecation")
public class AggregationTest extends ClientTest {
public class AggregationTest extends TestBase {

@BeforeClass
public static void prepare() {
TEST_INDEX = "test-index";
TestBase.prepare();
}

@AfterClass
public static void tearDown() {
TestBase.tearDown();
}

@Test
public void testAggregations() {
/**
Expand All @@ -30,7 +40,7 @@ public void testAggregations() {
127.0.0.1:6379> FT.ADD test_index data3 1.0 FIELDS name def count 25
*/

Client cl = getClient();
Client cl = getDefaultClient();
Schema sc = new Schema();
sc.addSortableTextField("name", 1.0);
sc.addSortableNumericField("count");
Expand Down Expand Up @@ -85,7 +95,7 @@ public void testApplyAndFilterAggregations() {
OK
*/

Client cl = getClient();
Client cl = getDefaultClient();
Schema sc = new Schema();
sc.addSortableTextField("name", 1.0);
sc.addSortableNumericField("subj1");
Expand Down Expand Up @@ -119,6 +129,7 @@ public void testApplyAndFilterAggregations() {
assertEquals("ghi", r2.getString("name"));
assertEquals(67.5, r2.getDouble("avgscore"), 0);
}

@Test
public void testCursor() throws InterruptedException {
/**
Expand All @@ -131,7 +142,7 @@ public void testCursor() throws InterruptedException {
127.0.0.1:6379> FT.ADD test_index data3 1.0 FIELDS name def count 25
*/

Client cl = getClient();
Client cl = getDefaultClient();
Schema sc = new Schema();
sc.addSortableTextField("name", 1.0);
sc.addSortableNumericField("count");
Expand Down
20 changes: 4 additions & 16 deletions src/test/java/io/redisearch/client/ClientJsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import io.redisearch.*;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.commands.ProtocolCommand;

import org.json.JSONObject;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.*;

public class ClientJsonTest {
public class ClientJsonTest extends TestBase {

public static final String JSON_ROOT = "$";

Expand All @@ -27,25 +25,15 @@ public byte[] getRaw() {
}
}

private static final String INDEX_NAME = "json-index";

private static Client search;

@BeforeClass
public static void prepare() {
search = new Client(INDEX_NAME, Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT);
}

@Before
public void setUp() {
try (Jedis j = search.connection()) {
j.flushAll();
}
TEST_INDEX = "json-index";
TestBase.prepare();
}

@AfterClass
public static void tearDown() {
search.close();
TestBase.tearDown();
}

private static void setJson(Jedis jedis, String key, JSONObject json) {
Expand Down
Loading

0 comments on commit 1ab1dcb

Please sign in to comment.