Skip to content

Commit 0f19b85

Browse files
committed
Test extraction of query ID from kill_query procedure
1 parent 5afabe0 commit 0f19b85

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

gateway-ha/src/test/java/io/trino/gateway/ha/handler/TestQueryIdCachingProxyHandler.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,27 @@
1313
*/
1414
package io.trino.gateway.ha.handler;
1515

16+
import jakarta.servlet.ReadListener;
17+
import jakarta.servlet.ServletInputStream;
1618
import jakarta.servlet.http.HttpServletRequest;
1719
import org.junit.jupiter.api.Test;
1820
import org.junit.jupiter.api.TestInstance;
1921
import org.junit.jupiter.api.TestInstance.Lifecycle;
2022
import org.mockito.Mockito;
2123

24+
import java.io.BufferedReader;
25+
import java.io.ByteArrayInputStream;
2226
import java.io.IOException;
27+
import java.io.Reader;
28+
import java.io.StringReader;
29+
import java.nio.charset.StandardCharsets;
2330

2431
import static io.trino.gateway.ha.handler.ProxyUtils.extractQueryIdIfPresent;
2532
import static io.trino.gateway.ha.handler.ProxyUtils.getQueryUser;
2633
import static io.trino.gateway.ha.handler.QueryIdCachingProxyHandler.AUTHORIZATION;
2734
import static io.trino.gateway.ha.handler.QueryIdCachingProxyHandler.USER_HEADER;
2835
import static org.assertj.core.api.Assertions.assertThat;
36+
import static org.mockito.Mockito.when;
2937

3038
@TestInstance(Lifecycle.PER_CLASS)
3139
public class TestQueryIdCachingProxyHandler
@@ -61,6 +69,44 @@ public void testExtractQueryIdFromUrl()
6169
.isNull();
6270
}
6371

72+
@Test
73+
public void testQueryIdFromKill()
74+
throws IOException
75+
{
76+
HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
77+
78+
String query = "CALL system.runtime.kill_query(query_id ==> '20200416_160256_03078_6b4yt', message ==> 'If he dies, he dies')";
79+
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(query.getBytes(StandardCharsets.UTF_8));
80+
when(req.getInputStream()).thenReturn(new ServletInputStream()
81+
{
82+
@Override
83+
public boolean isFinished()
84+
{
85+
return byteArrayInputStream.available() > 0;
86+
}
87+
88+
@Override
89+
public boolean isReady()
90+
{
91+
return true;
92+
}
93+
94+
@Override
95+
public void setReadListener(ReadListener readListener)
96+
{}
97+
98+
public int read()
99+
throws IOException
100+
{
101+
return byteArrayInputStream.read();
102+
}
103+
});
104+
105+
when(req.getQueryString()).thenReturn("");
106+
107+
assertThat(extractQueryIdIfPresent(req)).isEqualTo("20200416_160256_03078_6b4yt");
108+
}
109+
64110
@Test
65111
public void testUserFromRequest()
66112
throws IOException

0 commit comments

Comments
 (0)