Skip to content

Commit 0292941

Browse files
committed
Add integration tests
1 parent 3b493be commit 0292941

File tree

2 files changed

+127
-13
lines changed

2 files changed

+127
-13
lines changed

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseIntegrationTest.java

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
package com.scalar.db.storage.jdbc;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import com.scalar.db.api.DistributedStorage;
36
import com.scalar.db.api.DistributedStorageIntegrationTestBase;
7+
import com.scalar.db.api.Get;
8+
import com.scalar.db.api.Put;
9+
import com.scalar.db.api.Result;
10+
import com.scalar.db.api.Scan;
11+
import com.scalar.db.api.Scanner;
412
import com.scalar.db.config.DatabaseConfig;
13+
import com.scalar.db.exception.storage.ExecutionException;
14+
import com.scalar.db.io.Key;
15+
import com.scalar.db.service.StorageFactory;
16+
import java.io.IOException;
17+
import java.util.List;
18+
import java.util.Optional;
519
import java.util.Properties;
20+
import org.junit.jupiter.api.Test;
621

722
public class JdbcDatabaseIntegrationTest extends DistributedStorageIntegrationTestBase {
823

@@ -25,4 +40,103 @@ protected int getLargeDataSizeInBytes() {
2540
return super.getLargeDataSizeInBytes();
2641
}
2742
}
43+
44+
@Test
45+
public void get_InStreamingMode_ShouldRetrieveSingleResult() throws ExecutionException {
46+
try (DistributedStorage storage = getStorageInStreamingMode()) {
47+
// Arrange
48+
int pKey = 0;
49+
int cKey = 1;
50+
int value = 2;
51+
52+
storage.put(
53+
Put.newBuilder()
54+
.namespace(namespace)
55+
.table(TABLE)
56+
.partitionKey(Key.ofInt(COL_NAME1, pKey))
57+
.clusteringKey(Key.ofInt(COL_NAME4, cKey))
58+
.intValue(COL_NAME3, value)
59+
.build());
60+
61+
// Act
62+
Optional<Result> result =
63+
storage.get(
64+
Get.newBuilder()
65+
.namespace(namespace)
66+
.table(TABLE)
67+
.partitionKey(Key.ofInt(COL_NAME1, pKey))
68+
.clusteringKey(Key.ofInt(COL_NAME4, cKey))
69+
.build());
70+
71+
// Assert
72+
assertThat(result.isPresent()).isTrue();
73+
assertThat(result.get().getInt(COL_NAME1)).isEqualTo(pKey);
74+
assertThat(result.get().getInt(COL_NAME4)).isEqualTo(cKey);
75+
assertThat(result.get().getInt(COL_NAME3)).isEqualTo(value);
76+
}
77+
}
78+
79+
@Test
80+
public void scan_InStreamingMode_ShouldRetrieveResults() throws IOException, ExecutionException {
81+
try (DistributedStorage storage = getStorageInStreamingMode()) {
82+
// Arrange
83+
int pKey = 0;
84+
85+
storage.put(
86+
Put.newBuilder()
87+
.namespace(namespace)
88+
.table(TABLE)
89+
.partitionKey(Key.ofInt(COL_NAME1, pKey))
90+
.clusteringKey(Key.ofInt(COL_NAME4, 0))
91+
.intValue(COL_NAME3, 1)
92+
.build());
93+
storage.put(
94+
Put.newBuilder()
95+
.namespace(namespace)
96+
.table(TABLE)
97+
.partitionKey(Key.ofInt(COL_NAME1, pKey))
98+
.clusteringKey(Key.ofInt(COL_NAME4, 1))
99+
.intValue(COL_NAME3, 2)
100+
.build());
101+
storage.put(
102+
Put.newBuilder()
103+
.namespace(namespace)
104+
.table(TABLE)
105+
.partitionKey(Key.ofInt(COL_NAME1, pKey))
106+
.clusteringKey(Key.ofInt(COL_NAME4, 2))
107+
.intValue(COL_NAME3, 3)
108+
.build());
109+
110+
// Act
111+
Scanner scanner =
112+
storage.scan(
113+
Scan.newBuilder()
114+
.namespace(namespace)
115+
.table(TABLE)
116+
.partitionKey(Key.ofInt(COL_NAME1, pKey))
117+
.build());
118+
List<Result> results = scanner.all();
119+
scanner.close();
120+
121+
// Assert
122+
assertThat(results).hasSize(3);
123+
assertThat(results.get(0).getInt(COL_NAME1)).isEqualTo(pKey);
124+
assertThat(results.get(0).getInt(COL_NAME4)).isEqualTo(0);
125+
assertThat(results.get(0).getInt(COL_NAME3)).isEqualTo(1);
126+
127+
assertThat(results.get(1).getInt(COL_NAME1)).isEqualTo(pKey);
128+
assertThat(results.get(1).getInt(COL_NAME4)).isEqualTo(1);
129+
assertThat(results.get(1).getInt(COL_NAME3)).isEqualTo(2);
130+
131+
assertThat(results.get(2).getInt(COL_NAME1)).isEqualTo(pKey);
132+
assertThat(results.get(2).getInt(COL_NAME4)).isEqualTo(2);
133+
assertThat(results.get(2).getInt(COL_NAME3)).isEqualTo(3);
134+
}
135+
}
136+
137+
private DistributedStorage getStorageInStreamingMode() {
138+
Properties properties = JdbcEnv.getProperties(TEST_NAME);
139+
properties.setProperty(DatabaseConfig.SCAN_FETCH_SIZE, Integer.toString(Integer.MIN_VALUE));
140+
return StorageFactory.create(properties).getStorage();
141+
}
28142
}

integration-test/src/main/java/com/scalar/db/api/DistributedStorageIntegrationTestBase.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ public abstract class DistributedStorageIntegrationTestBase {
4747
private static final Logger logger =
4848
LoggerFactory.getLogger(DistributedStorageIntegrationTestBase.class);
4949

50-
private static final String TEST_NAME = "storage";
51-
private static final String NAMESPACE = "int_test_" + TEST_NAME;
52-
private static final String TABLE = "test_table";
53-
private static final String COL_NAME1 = "c1";
54-
private static final String COL_NAME2 = "c2";
55-
private static final String COL_NAME3 = "c3";
56-
private static final String COL_NAME4 = "c4";
57-
private static final String COL_NAME5 = "c5";
58-
private static final String COL_NAME6 = "c6";
59-
60-
private DistributedStorage storage;
61-
private DistributedStorageAdmin admin;
62-
private String namespace;
50+
protected static final String TEST_NAME = "storage";
51+
protected static final String NAMESPACE = "int_test_" + TEST_NAME;
52+
protected static final String TABLE = "test_table";
53+
protected static final String COL_NAME1 = "c1";
54+
protected static final String COL_NAME2 = "c2";
55+
protected static final String COL_NAME3 = "c3";
56+
protected static final String COL_NAME4 = "c4";
57+
protected static final String COL_NAME5 = "c5";
58+
protected static final String COL_NAME6 = "c6";
59+
60+
protected DistributedStorage storage;
61+
protected DistributedStorageAdmin admin;
62+
protected String namespace;
6363

6464
@BeforeAll
6565
public void beforeAll() throws Exception {

0 commit comments

Comments
 (0)