11package com .scalar .db .storage .jdbc ;
22
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import com .scalar .db .api .DistributedStorage ;
36import 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 ;
412import 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 ;
519import java .util .Properties ;
20+ import org .junit .jupiter .api .Test ;
621
722public 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}
0 commit comments