ChinmaySKulkarni commented on a change in pull request #749: PHOENIX-4521: 
Allow Pherf scenario to define per query max allowed query execution duration 
after which thread is interrupted
URL: https://github.com/apache/phoenix/pull/749#discussion_r402662860
 
 

 ##########
 File path: 
phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/MultiThreadedRunnerTest.java
 ##########
 @@ -0,0 +1,95 @@
+package org.apache.phoenix.pherf.workload;
+
+import javafx.util.Pair;
+import org.apache.phoenix.pherf.configuration.Query;
+import org.apache.phoenix.pherf.configuration.Scenario;
+import org.apache.phoenix.pherf.configuration.XMLConfigParser;
+import org.apache.phoenix.pherf.result.DataModelResult;
+import org.apache.phoenix.pherf.result.ThreadTime;
+import org.apache.phoenix.pherf.rules.RulesApplier;
+import org.apache.phoenix.util.EnvironmentEdge;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.sql.ResultSet;
+
+import static org.junit.Assert.*;
+
+public class MultiThreadedRunnerTest {
+
+    private static class MyClock extends EnvironmentEdge {
+
+        public MyClock () {}
+
+        @Override
+        public long currentTime() {
+            return System.currentTimeMillis();
+        }
+    }
+
+    @Test
+    public void testExpectedRowsMismatch() throws Exception {
+        XMLConfigParser parser = new 
XMLConfigParser(".*timeout_test_scenario.xml");
+        Query mockQuery = Mockito.mock(Query.class);
+        Mockito.when(mockQuery.getExpectedAggregateRowCount()).thenReturn(1L);
+        MultiThreadedRunner mtr = new MultiThreadedRunner("test", mockQuery,
+                new DataModelResult(), new ThreadTime(),
+                10, 1000,
+                true, new RulesApplier(parser),
+                new Scenario(), new WorkloadExecutor(), parser);
+        ResultSet mockRS = Mockito.mock(ResultSet.class);
+        Mockito.when(mockRS.next()).thenReturn(true);
+        Mockito.when(mockRS.getLong(1)).thenReturn(2L);
+        try {
+            mtr.getResults(mockRS, "test_iteration", false);
+            fail();
+        } catch (RuntimeException e) {
+            //pass;
+        }
+
+    }
+
+    @Test
+    public void testTimeout() throws Exception {
+        MyClock myClock = Mockito.mock(MyClock.class);
+        Mockito.when(myClock.currentTime()).thenReturn(0L,0L, 0L, 5000L); 
//currentTime() gets called twice during MTR construction
+        EnvironmentEdgeManager.injectEdge(myClock);
+        XMLConfigParser parser = new 
XMLConfigParser(".*timeout_test_scenario.xml");
+        Query mockQuery = Mockito.mock(Query.class);
+        Mockito.when(mockQuery.getTimeoutDuration()).thenReturn(1000L);
+        Mockito.when(mockQuery.getExpectedAggregateRowCount()).thenReturn(1L);
+        MultiThreadedRunner mtr = new MultiThreadedRunner("test", mockQuery,
+                new DataModelResult(), new ThreadTime(),
+                10, 1000,
+                true, new RulesApplier(parser),
+                new Scenario(), new WorkloadExecutor(), parser);
+        ResultSet mockRS = Mockito.mock(ResultSet.class);
+        Mockito.when(mockRS.next()).thenReturn(true);
+        Mockito.when(mockRS.getLong(1)).thenReturn(1L);
+        Pair<Long, Boolean> results = mtr.getResults(mockRS, "test_iteration", 
false);
+        assertTrue(results.getValue());
+    }
+
+    @Test
+    public void testFinishWithoutTimeout() throws Exception {
+        MyClock myClock = Mockito.mock(MyClock.class);
+        Mockito.when(myClock.currentTime()).thenReturn(0L); //currentTime() 
gets called twice during MTR construction
 
 Review comment:
   I think there's something wrong with this test. Can you please check?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to