6
6
package org .opensearch .sql .legacy .executor .join ;
7
7
8
8
import static org .junit .Assert .*;
9
- import static org .mockito .ArgumentMatchers .any ;
10
- import static org .mockito .ArgumentMatchers .eq ;
11
9
import static org .mockito .Mockito .*;
12
10
13
11
import java .util .ArrayList ;
14
12
import java .util .Arrays ;
13
+ import java .util .Collections ;
15
14
import java .util .List ;
15
+ import lombok .SneakyThrows ;
16
16
import org .junit .Before ;
17
17
import org .junit .Test ;
18
- import org .junit .runner .RunWith ;
19
18
import org .mockito .Mock ;
20
- import org .mockito .junit . MockitoJUnitRunner ;
19
+ import org .mockito .MockitoAnnotations ;
21
20
import org .opensearch .common .unit .TimeValue ;
21
+ import org .opensearch .search .SearchHit ;
22
+ import org .opensearch .sql .legacy .domain .Field ;
22
23
import org .opensearch .sql .legacy .domain .Select ;
23
24
import org .opensearch .sql .legacy .domain .hints .Hint ;
24
25
import org .opensearch .sql .legacy .domain .hints .HintType ;
25
- import org .opensearch .sql .legacy .pit .PointInTimeHandlerImpl ;
26
26
import org .opensearch .sql .legacy .query .join .JoinRequestBuilder ;
27
27
import org .opensearch .sql .legacy .query .join .TableInJoinRequestBuilder ;
28
28
import org .opensearch .transport .client .Client ;
29
29
30
- @ RunWith (MockitoJUnitRunner .class )
31
30
public class ElasticJoinExecutorTest {
32
31
33
- @ Mock
34
- private Client mockClient ;
35
-
36
- @ Mock
37
- private JoinRequestBuilder mockJoinRequestBuilder ;
38
-
39
- @ Mock
40
- private TableInJoinRequestBuilder mockFirstTable ;
41
-
42
- @ Mock
43
- private TableInJoinRequestBuilder mockSecondTable ;
44
-
45
- @ Mock
46
- private Select mockFirstSelect ;
47
-
48
- @ Mock
49
- private Select mockSecondSelect ;
32
+ @ Mock private Client mockClient ;
33
+ @ Mock private JoinRequestBuilder mockJoinRequestBuilder ;
34
+ @ Mock private TableInJoinRequestBuilder mockFirstTable ;
35
+ @ Mock private TableInJoinRequestBuilder mockSecondTable ;
36
+ @ Mock private Select mockFirstSelect ;
37
+ @ Mock private Select mockSecondSelect ;
50
38
51
39
private TestableElasticJoinExecutor executor ;
52
40
53
- // Concrete test implementation to access private methods
41
+ // Concrete test implementation to access private methods and test behavior
54
42
private static class TestableElasticJoinExecutor extends ElasticJoinExecutor {
55
43
56
44
public TestableElasticJoinExecutor (Client client , JoinRequestBuilder requestBuilder ) {
57
45
super (client , requestBuilder );
58
46
}
59
47
60
48
@ Override
61
- protected List <org . opensearch . search . SearchHit > innerRun () {
49
+ protected List <SearchHit > innerRun () {
62
50
return new ArrayList <>();
63
51
}
64
52
65
53
// Expose private methods for testing
66
54
public TimeValue testExtractJoinTimeoutFromHints () {
67
- return super . extractJoinTimeoutFromHints ();
55
+ return extractJoinTimeoutFromHints ();
68
56
}
69
57
70
58
public TimeValue testGetJoinTimeoutFromTable (TableInJoinRequestBuilder table ) {
71
- return super . getJoinTimeoutFromTable (table );
59
+ return getJoinTimeoutFromTable (table );
72
60
}
73
61
74
62
public TimeValue testFindJoinTimeoutInHints (List <Hint > hints ) {
75
- return super . findJoinTimeoutInHints (hints );
63
+ return findJoinTimeoutInHints (hints );
76
64
}
77
65
}
78
66
79
67
@ Before
80
68
public void setUp () {
81
- // Setup mock chain
69
+ MockitoAnnotations .initMocks (this );
70
+
71
+ // Setup mock chain for constructor requirements
82
72
when (mockJoinRequestBuilder .getFirstTable ()).thenReturn (mockFirstTable );
83
73
when (mockJoinRequestBuilder .getSecondTable ()).thenReturn (mockSecondTable );
84
74
when (mockFirstTable .getOriginalSelect ()).thenReturn (mockFirstSelect );
@@ -284,7 +274,7 @@ public void testExtractJoinTimeoutFromHints_ExceptionHandling() {
284
274
285
275
@ Test
286
276
public void testBoundaryValues () {
287
- // Test various timeout values
277
+ // Test various timeout values that might be used in real scenarios
288
278
int [] testValues = {1 , 30 , 60 , 90 , 300 , 3600 , 7200 }; // 1s to 2hrs
289
279
290
280
for (int timeoutSeconds : testValues ) {
@@ -301,6 +291,39 @@ public void testBoundaryValues() {
301
291
}
302
292
}
303
293
294
+ @ Test
295
+ public void testTypicalJoinTimeoutScenarios () {
296
+ // Test common JOIN_TIME_OUT scenarios
297
+ int [] commonTimeouts = {90 , 180 , 300 , 600 }; // 1.5min, 3min, 5min, 10min
298
+
299
+ for (int timeout : commonTimeouts ) {
300
+ // Arrange
301
+ List <Hint > hints = createJoinTimeoutHints (timeout );
302
+ when (mockFirstSelect .getHints ()).thenReturn (hints );
303
+ when (mockSecondSelect .getHints ()).thenReturn (new ArrayList <>());
304
+
305
+ // Act
306
+ TimeValue result = executor .testExtractJoinTimeoutFromHints ();
307
+
308
+ // Assert
309
+ assertNotNull ("Should extract JOIN_TIME_OUT(" + timeout + ")" , result );
310
+ assertEquals ("Should extract " + timeout + " seconds" , timeout , result .getSeconds ());
311
+ }
312
+ }
313
+
314
+ @ Test
315
+ public void testConstructorStoresRequestBuilder () {
316
+ // Verify that the constructor properly stores the request builder for hint access
317
+ assertNotNull ("Executor should be created successfully" , executor );
318
+
319
+ // Test that the executor can access hints through the stored request builder
320
+ List <Hint > hints = createJoinTimeoutHints (90 );
321
+ when (mockFirstSelect .getHints ()).thenReturn (hints );
322
+
323
+ TimeValue result = executor .testExtractJoinTimeoutFromHints ();
324
+ assertNotNull ("Should be able to access hints through stored request builder" , result );
325
+ }
326
+
304
327
// Helper Methods
305
328
306
329
private List <Hint > createJoinTimeoutHints (int timeoutSeconds ) {
0 commit comments