Skip to content

Commit

Permalink
[Test] test case for limit & offset (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
IHEII authored Feb 26, 2024
1 parent abab370 commit 31dcb8c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/test/java/com/alipay/oceanbase/rpc/ObTableTTLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.alipay.oceanbase.rpc;

import com.alipay.oceanbase.rpc.filter.ObCompareOp;
import com.alipay.oceanbase.rpc.mutation.*;
import com.alipay.oceanbase.rpc.mutation.result.MutationResult;
import com.alipay.oceanbase.rpc.stream.QueryResultSet;
Expand All @@ -29,6 +30,7 @@
import java.sql.Timestamp;
import java.util.Map;

import static com.alipay.oceanbase.rpc.filter.ObTableFilterFactory.compareVal;
import static com.alipay.oceanbase.rpc.mutation.MutationFactory.colVal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -93,7 +95,64 @@ public void testQuery() throws Exception {
client.delete(tableName).setRowKey(colVal(keyCol, id)).execute();
}
}
}

@Test
public void testQueryOffset() throws Exception {
long[] keyIds = { 1L, 2L, 3L, 4L};
String tableName = "test_ttl_timestamp_5s";
try {
Timestamp curTs = new Timestamp(System.currentTimeMillis());

// 1. insert records with current expired_ts
client.insert(tableName).setRowKey(colVal(keyCol, 1L))
.addMutateColVal(colVal(valueCol, defaultValue))
.addMutateColVal(colVal(expireCol, curTs)).execute();

client.insert(tableName).setRowKey(colVal(keyCol, 2L))
.addMutateColVal(colVal(valueCol, defaultValue))
.addMutateColVal(colVal(expireCol, curTs)).execute();

client.insert(tableName).setRowKey(colVal(keyCol, 3L))
.addMutateColVal(colVal(valueCol, defaultValue))
.addMutateColVal(colVal(expireCol, null)).execute();

client.insert(tableName).setRowKey(colVal(keyCol, 4L))
.addMutateColVal(colVal(valueCol, defaultValue))
.addMutateColVal(colVal(expireCol, null)).execute();

//+----+-------------+------+----------------------------+
//| c1 | c2 | c3 | expired_ts |
//+----+-------------+------+----------------------------+
//| 1 | hello world | NULL | xxx |
//| 2 | hello world | NULL | xxx |
//| 3 | hello world | NULL | NULL |
//| 4 | hello world | NULL | NULL |
//+----+-------------+------+----------------------------+
Thread.sleep(6000);

// 2. query offset-2
QueryResultSet resultSet = client.query(tableName).addScanRange(keyIds[0], keyIds[3]).limit(2,4)
.execute();
Assert.assertEquals(resultSet.cacheSize(), 0);

// 2. query offset-0 && limit-2 and c1 >= 0
resultSet = client.query(tableName).addScanRange(keyIds[0], keyIds[3]).limit(0,2).setFilter(compareVal(ObCompareOp.GE, keyCol, 0))
.execute();
Assert.assertEquals(resultSet.cacheSize(), 2);

// 3. query offset-2 && limit-2 and c1 >= 0
resultSet = client.query(tableName).addScanRange(keyIds[0], keyIds[3]).limit(2,2).setFilter(compareVal(ObCompareOp.GE, keyCol, 0))
.execute();
Assert.assertEquals(resultSet.cacheSize(), 0);
} catch (Exception e) {
e.printStackTrace();
Assert.assertTrue(false);
} finally {
for (long id : keyIds) {
client.delete(tableName).setRowKey(colVal(keyCol, id)).execute();
}
}
}

@Test
Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/ci.sql
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ CREATE TABLE `test_ttl_timestamp` (
`expired_ts` timestamp(6),
PRIMARY KEY (`c1`)) TTL(expired_ts + INTERVAL 0 SECOND);

CREATE TABLE `test_ttl_timestamp_5s` (
`c1` bigint NOT NULL,
`c2` varchar(20) DEFAULT NULL,
`c3` bigint DEFAULT NULL,
`expired_ts` timestamp(6),
PRIMARY KEY (`c1`)) TTL(expired_ts + INTERVAL 5 SECOND);

CREATE TABLE IF NOT EXISTS `test_auto_increment_rowkey` (
`c1` int auto_increment,
`c2` int NOT NULL,
Expand Down

0 comments on commit 31dcb8c

Please sign in to comment.