File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
test/framework/src/main/java/org/elasticsearch/test
x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -275,6 +275,11 @@ public static void resetPortCounter() {
275275
276276 private static final SetOnce <Boolean > WARN_SECURE_RANDOM_FIPS_NOT_DETERMINISTIC = new SetOnce <>();
277277
278+ private static final String LOWER_ALPHA_CHARACTERS = "abcdefghijklmnopqrstuvwxyz" ;
279+ private static final String UPPER_ALPHA_CHARACTERS = LOWER_ALPHA_CHARACTERS .toUpperCase (Locale .ROOT );
280+ private static final String DIGIT_CHARACTERS = "0123456789" ;
281+ private static final String ALPHANUMERIC_CHARACTERS = LOWER_ALPHA_CHARACTERS + UPPER_ALPHA_CHARACTERS + DIGIT_CHARACTERS ;
282+
278283 static {
279284 Random random = initTestSeed ();
280285 TEST_WORKER_VM_ID = System .getProperty (TEST_WORKER_SYS_PROPERTY , DEFAULT_TEST_WORKER_ID );
@@ -1195,6 +1200,21 @@ public static String randomAlphaOfLength(int codeUnits) {
11951200 return RandomizedTest .randomAsciiOfLength (codeUnits );
11961201 }
11971202
1203+ /**
1204+ * Generate a random string containing only alphanumeric characters.
1205+ * @param length the length of the string to generate
1206+ * @return the generated string
1207+ */
1208+ public static String randomAlphanumericOfLength (int length ) {
1209+ StringBuilder sb = new StringBuilder ();
1210+ Random random = random ();
1211+ for (int i = 0 ; i < length ; i ++) {
1212+ sb .append (ALPHANUMERIC_CHARACTERS .charAt (random .nextInt (ALPHANUMERIC_CHARACTERS .length ())));
1213+ }
1214+
1215+ return sb .toString ();
1216+ }
1217+
11981218 public static SecureString randomSecureStringOfLength (int codeUnits ) {
11991219 var randomAlpha = randomAlphaOfLength (codeUnits );
12001220 return new SecureString (randomAlpha .toCharArray ());
Original file line number Diff line number Diff line change @@ -312,7 +312,7 @@ public void testSupportedStream() throws Exception {
312312 assertEquals (modelId , singleModel .get ("inference_id" ));
313313 assertEquals (TaskType .COMPLETION .toString (), singleModel .get ("task_type" ));
314314
315- var input = IntStream .range (1 , 2 + randomInt (8 )).mapToObj (i -> randomUUID ( )).toList ();
315+ var input = IntStream .range (1 , 2 + randomInt (8 )).mapToObj (i -> randomAlphanumericOfLength ( 5 )).toList ();
316316 try {
317317 var events = streamInferOnMockService (modelId , TaskType .COMPLETION , input );
318318
@@ -339,7 +339,7 @@ public void testUnifiedCompletionInference() throws Exception {
339339 assertEquals (modelId , singleModel .get ("inference_id" ));
340340 assertEquals (TaskType .COMPLETION .toString (), singleModel .get ("task_type" ));
341341
342- var input = IntStream .range (1 , 2 + randomInt (8 )).mapToObj (i -> randomUUID ( )).toList ();
342+ var input = IntStream .range (1 , 2 + randomInt (8 )).mapToObj (i -> randomAlphanumericOfLength ( 5 )).toList ();
343343 try {
344344 var events = unifiedCompletionInferOnMockService (modelId , TaskType .COMPLETION , input );
345345 var expectedResponses = expectedResultsIterator (input );
You can’t perform that action at this time.
0 commit comments