Skip to content

Commit 115528a

Browse files
committed
Add tests backward compatibility
1 parent 3209c4f commit 115528a

File tree

2 files changed

+90
-57
lines changed

2 files changed

+90
-57
lines changed

query/src/test/java/tech/ydb/query/impl/QueryIntegrationResourcePoolTest.java

Lines changed: 86 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,43 @@
55
import org.slf4j.LoggerFactory;
66

77
import tech.ydb.common.transaction.TxMode;
8-
import tech.ydb.core.Issue;
98
import tech.ydb.core.Result;
10-
import tech.ydb.core.Status;
11-
import tech.ydb.core.StatusCode;
129
import tech.ydb.query.QueryClient;
1310
import tech.ydb.query.QuerySession;
14-
import tech.ydb.query.QueryStream;
15-
import tech.ydb.query.QueryTransaction;
1611
import tech.ydb.query.result.QueryInfo;
17-
import tech.ydb.query.result.QueryResultPart;
1812
import tech.ydb.query.settings.ExecuteQuerySettings;
1913
import tech.ydb.query.settings.QueryExecMode;
2014
import tech.ydb.query.settings.QueryStatsMode;
21-
import tech.ydb.query.tools.QueryReader;
2215
import tech.ydb.table.SessionRetryContext;
2316
import tech.ydb.table.description.TableDescription;
2417
import tech.ydb.table.impl.SimpleTableClient;
2518
import tech.ydb.table.query.Params;
26-
import tech.ydb.table.result.ResultSetReader;
2719
import tech.ydb.table.rpc.grpc.GrpcTableRpc;
2820
import tech.ydb.table.values.PrimitiveType;
29-
import tech.ydb.table.values.PrimitiveValue;
3021
import tech.ydb.test.junit4.GrpcTransportRule;
3122

3223
import java.time.Duration;
33-
import java.util.ArrayList;
34-
import java.util.Iterator;
35-
import java.util.List;
36-
import java.util.concurrent.CompletableFuture;
3724

3825
/**
3926
* Test on resource poll.
27+
* <p>
4028
* Take an account, that resource poll with name "default" exists every time and can't be deleted
4129
* Also when we specify pool with empty string "" it's equivalent to default pool
30+
* <p>
31+
* Test marked with @Ignore should be uncommented when resource pool disappeared from experimental feature
32+
* <p>
33+
* Until this to run test go to @see tech.ydb.test.integration.YdbEnvironment
34+
* {@link tech.ydb.test.integration.YdbEnvironment}
35+
* dockerFeatures = createParam("YDB_DOCKER_FEATURE_FLAGS", "enable_resource_pools");
36+
* By the way feature available with image ydbplatform/local-ydb:24.3.11.13";
4237
*
4338
* @author Evgeny Kuvardin
4439
*/
4540
public class QueryIntegrationResourcePoolTest {
4641
private final static Logger logger = LoggerFactory.getLogger(QueryIntegrationResourcePoolTest.class);
47-
private final static String TEST_TABLE = "query_service_test";
48-
private final static String TEST_DOUBLE_TABLE = "query_double_table";
42+
private final static String TEST_TABLE = "query_resource_pool_service_test";
4943
private final static String TEST_RESOURCE_POOL = "test_pool";
44+
private final static String TEST_RESOURCE_POOL_WITH_DELETE = "test_pool_fot_delete";
5045

5146

5247
@ClassRule
@@ -60,87 +55,94 @@ public static void initSchema() {
6055
TableDescription tableDescription = TableDescription.newBuilder()
6156
.addNonnullColumn("id", PrimitiveType.Int32)
6257
.addNullableColumn("name", PrimitiveType.Text)
63-
.addNullableColumn("payload", PrimitiveType.Bytes)
64-
.addNullableColumn("is_valid", PrimitiveType.Bool)
65-
.setPrimaryKey("id")
66-
.build();
67-
68-
69-
String table2Path = ydbTransport.getDatabase() + "/" + TEST_DOUBLE_TABLE;
70-
TableDescription table2Description = TableDescription.newBuilder()
71-
.addNonnullColumn("id", PrimitiveType.Int32)
72-
.addNullableColumn("amount", PrimitiveType.Double)
7358
.setPrimaryKey("id")
7459
.build();
7560

7661
SimpleTableClient client = SimpleTableClient.newClient(GrpcTableRpc.useTransport(ydbTransport)).build();
7762
SessionRetryContext retryCtx = SessionRetryContext.create(client).build();
78-
retryCtx.supplyStatus(session -> session.createTable(tablePath, tableDescription)).join();
79-
retryCtx.supplyStatus(session -> session.createTable(table2Path, table2Description)).join();
63+
Assert.assertTrue("Table should be created before tests",
64+
retryCtx.supplyStatus(session -> session.createTable(tablePath, tableDescription)).join().isSuccess());
8065
logger.info("Prepare database OK");
8166

82-
try (QueryClient queryClient = QueryClient.newClient(ydbTransport).build()) {
83-
try (QuerySession querySession = queryClient.createSession(Duration.ofSeconds(5)).join().getValue()) {
84-
Result<QueryInfo> result = querySession.createQuery("CREATE RESOURCE POOL " + TEST_RESOURCE_POOL + " WITH (\n" +
85-
" CONCURRENT_QUERY_LIMIT=10,\n" +
86-
" QUEUE_SIZE=1000,\n" +
87-
" DATABASE_LOAD_CPU_THRESHOLD=80,\n" +
88-
" TOTAL_CPU_LIMIT_PERCENT_PER_NODE=70);", TxMode.NONE).execute().join();
89-
90-
Assert.assertTrue(result.getValue().toString(), result.isSuccess());
91-
}
92-
}
9367
}
9468

9569
@AfterClass
9670
public static void dropAll() {
9771
logger.info("Clean database...");
9872
String tablePath = ydbTransport.getDatabase() + "/" + TEST_TABLE;
99-
String table2Path = ydbTransport.getDatabase() + "/" + TEST_DOUBLE_TABLE;
10073

10174
SimpleTableClient client = SimpleTableClient.newClient(GrpcTableRpc.useTransport(ydbTransport)).build();
10275
SessionRetryContext retryCtx = SessionRetryContext.create(client).build();
103-
retryCtx.supplyStatus(session -> session.dropTable(tablePath)).join().isSuccess();
104-
retryCtx.supplyStatus(session -> session.dropTable(table2Path)).join().isSuccess();
105-
106-
try (QueryClient queryClient = QueryClient.newClient(ydbTransport).build()) {
107-
try (QuerySession querySession = queryClient.createSession(Duration.ofSeconds(5)).join().getValue()) {
108-
Result<QueryInfo> result = querySession.createQuery("DROP RESOURCE POOL " + TEST_RESOURCE_POOL + ";", TxMode.NONE).execute().join();
109-
110-
Assert.assertTrue(result.getValue().toString(), result.isSuccess());
111-
}
112-
}
76+
retryCtx.supplyStatus(session -> session.dropTable(tablePath)).join();
11377

11478
logger.info("Clean database OK");
11579
}
11680

81+
@Ignore
11782
@Test
11883
public void selectWithResourcePoolTest() {
84+
createResourcePool(TEST_RESOURCE_POOL);
11985
try (QueryClient client = QueryClient.newClient(ydbTransport).build()) {
12086
try (QuerySession session = client.createSession(Duration.ofSeconds(5)).join().getValue()) {
12187
ExecuteQuerySettings settings = ExecuteQuerySettings.newBuilder()
12288
.withExecMode(QueryExecMode.EXECUTE)
12389
.withResourcePool("test_pool")
90+
.withStatsMode(QueryStatsMode.FULL)
12491
.build();
12592

126-
Assert.assertTrue("Query shouldn't fall",
127-
session.createQuery("SELECT 2 + 3;", TxMode.SERIALIZABLE_RW, Params.empty(), settings).execute()
93+
Assert.assertTrue("Query shouldn't fail",
94+
session.createQuery("SELECT id, name FROM " + TEST_TABLE + " ORDER BY id;", TxMode.SERIALIZABLE_RW, Params.empty(), settings).execute()
12895
.join().isSuccess());
12996
}
97+
} finally {
98+
deleteResourcePool(TEST_RESOURCE_POOL, true);
13099
}
131100
}
132101

102+
/**
103+
* Check that we don't cache resource pool in session
104+
*/
105+
@Ignore
106+
@Test
107+
public void selectWithResourcePoolShouldNotCachePoolInSessionTest() {
108+
createResourcePool(TEST_RESOURCE_POOL_WITH_DELETE);
109+
110+
try (QueryClient client = QueryClient.newClient(ydbTransport).build()) {
111+
try (QuerySession session = client.createSession(Duration.ofSeconds(5)).join().getValue()) {
112+
ExecuteQuerySettings settings = ExecuteQuerySettings.newBuilder()
113+
.withExecMode(QueryExecMode.EXECUTE)
114+
.withResourcePool(TEST_RESOURCE_POOL_WITH_DELETE)
115+
.withStatsMode(QueryStatsMode.FULL)
116+
.build();
117+
118+
Assert.assertTrue("Query shouldn't fail",
119+
session.createQuery("SELECT id, name FROM " + TEST_TABLE + " ORDER BY id;", TxMode.SERIALIZABLE_RW, Params.empty(), settings).execute()
120+
.join().isSuccess());
121+
122+
deleteResourcePool(TEST_RESOURCE_POOL_WITH_DELETE, true);
123+
124+
Assert.assertTrue("Query shouldn't cache in session previous call to resource pool",
125+
session.createQuery("SELECT id, name FROM " + TEST_TABLE + " ORDER BY id;", TxMode.SERIALIZABLE_RW, Params.empty()).execute()
126+
.join().isSuccess());
127+
}
128+
} finally {
129+
deleteResourcePool(TEST_RESOURCE_POOL_WITH_DELETE, false);
130+
}
131+
}
132+
133+
133134
@Test
134135
public void selectWithDefaultResourcePoolTest() {
135136
try (QueryClient client = QueryClient.newClient(ydbTransport).build()) {
136137
try (QuerySession session = client.createSession(Duration.ofSeconds(5)).join().getValue()) {
137138
ExecuteQuerySettings settings = ExecuteQuerySettings.newBuilder()
138139
.withExecMode(QueryExecMode.EXECUTE)
139140
.withResourcePool("default")
141+
.withStatsMode(QueryStatsMode.FULL)
140142
.build();
141143

142-
Assert.assertTrue("Query shouldn't fall",
143-
session.createQuery("SELECT 2 + 3;", TxMode.SERIALIZABLE_RW, Params.empty(), settings).execute()
144+
Assert.assertTrue("Query shouldn't fail with default pool name",
145+
session.createQuery("SELECT id, name FROM " + TEST_TABLE + " ORDER BY id;", TxMode.SERIALIZABLE_RW, Params.empty(), settings).execute()
144146
.join().isSuccess());
145147
}
146148
}
@@ -155,26 +157,53 @@ public void selectWithDefaultResourcePoolAndEmptyStringTest() {
155157
.withResourcePool("")
156158
.build();
157159

158-
Assert.assertTrue("Query shouldn't fall",
159-
session.createQuery("SELECT 2 + 3;", TxMode.SERIALIZABLE_RW, Params.empty(), settings).execute()
160+
Assert.assertTrue("Query shouldn't fail cause empty string equivalent to default pool.",
161+
session.createQuery("SELECT id, name FROM " + TEST_TABLE + " ORDER BY id;", TxMode.SERIALIZABLE_RW, Params.empty(), settings).execute()
160162
.join().isSuccess());
161163
}
162164
}
163165
}
164166

167+
@Ignore
165168
@Test
166169
public void selectShouldFailWithUnknownResourcePollTest() {
167170
try (QueryClient client = QueryClient.newClient(ydbTransport).build()) {
168171
try (QuerySession session = client.createSession(Duration.ofSeconds(5)).join().getValue()) {
169172
ExecuteQuerySettings settings = ExecuteQuerySettings.newBuilder()
170173
.withExecMode(QueryExecMode.EXECUTE)
171174
.withResourcePool("some_unknown_pool")
175+
.withStatsMode(QueryStatsMode.FULL)
172176
.build();
173177

174-
Assert.assertFalse("Query should fall",
175-
session.createQuery("SELECT 2 + 3;", TxMode.SERIALIZABLE_RW, Params.empty(), settings).execute()
178+
Assert.assertFalse("Query should fail cause poll not exists",
179+
session.createQuery("SELECT id, name FROM " + TEST_TABLE + " ORDER BY id;", TxMode.SERIALIZABLE_RW, Params.empty(), settings).execute()
176180
.join().isSuccess());
177181
}
178182
}
179183
}
184+
185+
private static void createResourcePool(String resourcePoolName) {
186+
try (QueryClient queryClient = QueryClient.newClient(ydbTransport).build()) {
187+
try (QuerySession querySession = queryClient.createSession(Duration.ofSeconds(5)).join().getValue()) {
188+
Result<QueryInfo> result = querySession.createQuery("CREATE RESOURCE POOL " + resourcePoolName + " WITH (\n" +
189+
" CONCURRENT_QUERY_LIMIT=10,\n" +
190+
" QUEUE_SIZE=1000,\n" +
191+
" DATABASE_LOAD_CPU_THRESHOLD=80);", TxMode.NONE).execute().join();
192+
193+
Assert.assertTrue(result.getStatus().toString(), result.isSuccess());
194+
}
195+
}
196+
}
197+
198+
private static void deleteResourcePool(String resourcePoolName, boolean checkError) {
199+
try (QueryClient queryClient = QueryClient.newClient(ydbTransport).build()) {
200+
try (QuerySession querySession = queryClient.createSession(Duration.ofSeconds(5)).join().getValue()) {
201+
Result<QueryInfo> result = querySession.createQuery("DROP RESOURCE POOL " + resourcePoolName + ";", TxMode.NONE).execute().join();
202+
203+
if (checkError) {
204+
Assert.assertTrue(result.getStatus().toString(), result.isSuccess());
205+
}
206+
}
207+
}
208+
}
180209
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package tech.ydb.query.impl;
2+
3+
public class SessionImplTest {
4+
}

0 commit comments

Comments
 (0)