5858import java .util .Map ;
5959import java .util .Properties ;
6060import java .util .Set ;
61+ import java .util .concurrent .CountDownLatch ;
62+ import java .util .concurrent .ExecutorService ;
63+ import java .util .concurrent .Executors ;
64+ import java .util .concurrent .Future ;
6165import java .util .concurrent .TimeUnit ;
6266import java .util .stream .Collectors ;
6367import java .util .stream .Stream ;
@@ -180,11 +184,89 @@ public void testTableModelReadWrite() throws SQLException {
180184 }
181185 }
182186
187+ @ Test
188+ public void testConcurrentTableQueriesWithSmallThreadPools () throws Exception {
189+ try (Connection connection = openTableConnection ();
190+ Statement statement = connection .createStatement ()) {
191+ statement .execute ("CREATE DATABASE edge_it_concurrent" );
192+ statement .execute ("USE edge_it_concurrent" );
193+ statement .execute ("CREATE TABLE sensor(device STRING TAG, value INT32 FIELD)" );
194+ statement .execute ("INSERT INTO sensor(time,device,value) VALUES (1,'d1',42), (2,'d1',84)" );
195+ }
196+
197+ ExecutorService executor = Executors .newFixedThreadPool (4 );
198+ CountDownLatch ready = new CountDownLatch (4 );
199+ CountDownLatch start = new CountDownLatch (1 );
200+ List <Future <Void >> queries = new ArrayList <>();
201+ try {
202+ for (int i = 0 ; i < 4 ; i ++) {
203+ queries .add (
204+ executor .submit (
205+ () -> {
206+ try (Connection connection = openTableConnection ();
207+ Statement statement = connection .createStatement ()) {
208+ statement .execute ("USE edge_it_concurrent" );
209+ ready .countDown ();
210+ assertTrue (start .await (30 , TimeUnit .SECONDS ));
211+ for (int iteration = 0 ; iteration < 20 ; iteration ++) {
212+ try (ResultSet result =
213+ statement .executeQuery ("SELECT sum(value) FROM sensor" )) {
214+ assertTrue (result .next ());
215+ assertEquals (126.0 , result .getDouble (1 ), 0.0 );
216+ assertFalse (result .next ());
217+ }
218+ try (ResultSet result =
219+ statement .executeQuery (
220+ "SELECT value FROM sensor WHERE device='d1' ORDER BY time" )) {
221+ assertTrue (result .next ());
222+ assertEquals (42 , result .getInt (1 ));
223+ assertTrue (result .next ());
224+ assertEquals (84 , result .getInt (1 ));
225+ assertFalse (result .next ());
226+ }
227+ }
228+ }
229+ return null ;
230+ }));
231+ }
232+ assertTrue (ready .await (30 , TimeUnit .SECONDS ));
233+ start .countDown ();
234+ for (Future <Void > query : queries ) {
235+ query .get (60 , TimeUnit .SECONDS );
236+ }
237+ } finally {
238+ start .countDown ();
239+ executor .shutdownNow ();
240+ assertTrue (executor .awaitTermination (10 , TimeUnit .SECONDS ));
241+ }
242+ }
243+
183244 private static Connection openTreeConnection () throws SQLException {
184245 return DriverManager .getConnection (
185246 jdbcUrl (), SessionConfig .DEFAULT_USER , SessionConfig .DEFAULT_PASSWORD );
186247 }
187248
249+ @ Test
250+ public void testRatisMetadataConsensus () throws SQLException {
251+ Map <String , String > variables = new LinkedHashMap <>();
252+ try (Connection connection = openTableConnection ();
253+ Statement statement = connection .createStatement ();
254+ ResultSet result = statement .executeQuery ("SHOW VARIABLES" )) {
255+ while (result .next ()) {
256+ variables .put (result .getString (1 ), result .getString (2 ));
257+ }
258+ }
259+ assertEquals (
260+ "org.apache.iotdb.consensus.ratis.RatisConsensus" ,
261+ variables .get ("ConfigNodeConsensusProtocolClass" ));
262+ assertEquals (
263+ "org.apache.iotdb.consensus.ratis.RatisConsensus" ,
264+ variables .get ("SchemaRegionConsensusProtocolClass" ));
265+ assertEquals (
266+ "org.apache.iotdb.consensus.iot.IoTConsensus" ,
267+ variables .get ("DataRegionConsensusProtocolClass" ));
268+ }
269+
188270 private static Connection openTableConnection () throws SQLException {
189271 return DriverManager .getConnection (
190272 jdbcUrl () + "?sql_dialect=table" ,
@@ -195,6 +277,10 @@ private static Connection openTableConnection() throws SQLException {
195277 @ Test
196278 public void testPackagedConfiguration () throws Exception {
197279 assertFalse (PACKAGED_SYSTEM_PROPERTIES .containsKey ("model_inference_execution_thread_count" ));
280+ assertEdgeProperty ("coordinator_read_executor_size" , "2" );
281+ assertEdgeProperty ("coordinator_scheduled_executor_size" , "2" );
282+ assertEdgeProperty ("fragment_instance_notification_thread_count" , "2" );
283+ assertEdgeProperty ("cn_load_statistics_publisher_thread_count" , "1" );
198284 assertEdgeProperty ("candidate_compaction_task_queue_size" , "10" );
199285 assertEdgeProperty ("compaction_max_aligned_series_num_in_one_batch" , "2" );
200286 assertEdgeProperty ("target_compaction_file_size" , "33554432" );
0 commit comments