Skip to content

Commit 1ad0e45

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

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,24 @@
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.ByteArrayInputStream;
2225
import java.io.IOException;
26+
import java.nio.charset.StandardCharsets;
2327

2428
import static io.trino.gateway.ha.handler.ProxyUtils.extractQueryIdIfPresent;
2529
import static io.trino.gateway.ha.handler.ProxyUtils.getQueryUser;
2630
import static io.trino.gateway.ha.handler.QueryIdCachingProxyHandler.AUTHORIZATION;
2731
import static io.trino.gateway.ha.handler.QueryIdCachingProxyHandler.USER_HEADER;
2832
import static org.assertj.core.api.Assertions.assertThat;
33+
import static org.mockito.Mockito.when;
2934

3035
@TestInstance(Lifecycle.PER_CLASS)
3136
public class TestQueryIdCachingProxyHandler
@@ -61,6 +66,44 @@ public void testExtractQueryIdFromUrl()
6166
.isNull();
6267
}
6368

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

0 commit comments

Comments
 (0)