changeset 1092:27e2ec3b81a6

MySqlResponsePacketsDecoder - bugfixes
author Devel 2
date Mon, 11 May 2020 11:59:02 +0200
parents fb3d83dfbd17
children f48d0f6748e6
files stress-tester/src/main/java/com/passus/st/client/mysql/MySqlResponsePacketsDecoder.java stress-tester/src/test/java/com/passus/st/client/mysql/MySqlResponsePacketsDecoderTest.java stress-tester/src/test/resources/pcap/mysql/mysql_greeting_login.pcap stress-tester/src/test/resources/pcap/mysql/mysql_select_db_query.pcap stress-tester/src/test/resources/pcap/mysql/mysql_show_fields_req_res.pcap stress-tester/src/test/resources/pcap/mysql/mysql_use_db.pcap
diffstat 6 files changed, 65 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlResponsePacketsDecoder.java	Mon May 11 10:59:57 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlResponsePacketsDecoder.java	Mon May 11 11:59:02 2020 +0200
@@ -84,7 +84,8 @@
                     MySqlPacket packet = decoder.getResult();
                     if (packet != null) {
                         packets.add(packet);
-                        if (context.stage() == MySqlDecoderContext.STAGE_REQUEST) {
+                        if (context.stage() == MySqlDecoderContext.STAGE_REQUEST
+                                || context.stage() == MySqlDecoderContext.STAGE_NONE) {
                             state(STATE_FINISHED);
                         }
                     }
--- a/stress-tester/src/test/java/com/passus/st/client/mysql/MySqlResponsePacketsDecoderTest.java	Mon May 11 10:59:57 2020 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/mysql/MySqlResponsePacketsDecoderTest.java	Mon May 11 11:59:02 2020 +0200
@@ -12,11 +12,51 @@
 import static com.passus.data.DataDecoder.STATE_DATA_NEEDED;
 import static com.passus.data.DataDecoder.STATE_FINISHED;
 import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
 
 public class MySqlResponsePacketsDecoderTest {
-    
+
     @Test
-    public void testProcess1000Records() {
+    public void testLogin() {
+        List<Tcp> tcps = PcapUtils.readTcpPackets("pcap/mysql/mysql_greeting_login.pcap");
+
+        MySqlDecoderContext context = new MySqlDecoderContext();
+        MySqlRequestDecoder reqDecoder = new MySqlRequestDecoder(context);
+        MySqlResponsePacketsDecoder respDecoder = new MySqlResponsePacketsDecoder(context);
+
+        Iterator<Tcp> it = tcps.iterator();
+        respDecoder.decode(it.next().getPayload());
+        assertEquals(STATE_FINISHED, respDecoder.state());
+
+        List<MySqlPacket> packets = respDecoder.getResult();
+        assertEquals(1, packets.size());
+        assertTrue(packets.get(0) instanceof MySqlServerGreetingResponse);
+
+        reqDecoder.decode(it.next().getPayload());
+        assertEquals(STATE_FINISHED, reqDecoder.state());
+
+        assertTrue(reqDecoder.getResult() instanceof MySqlLoginRequest);
+    }
+
+    @Test
+    public void testUseDb() {
+        List<Tcp> tcps = PcapUtils.readTcpPackets("pcap/mysql/mysql_use_db.pcap");
+
+        MySqlDecoderContext context = new MySqlDecoderContext();
+        MySqlRequestDecoder reqDecoder = new MySqlRequestDecoder(context);
+        MySqlResponsePacketsDecoder respDecoder = new MySqlResponsePacketsDecoder(context);
+
+        Iterator<Tcp> it = tcps.iterator();
+        reqDecoder.decode(it.next().getPayload());
+        assertEquals(STATE_FINISHED, reqDecoder.state());
+        assertTrue(reqDecoder.getResult() instanceof MySqlUseDatabaseCommand);
+
+        respDecoder.decode(it.next().getPayload());
+        assertEquals(STATE_FINISHED, respDecoder.state());
+    }
+
+    @Test
+    public void testQuery1000Records() {
         List<Tcp> tcps = PcapUtils.readTcpPackets("pcap/mysql/mysql_query_1000_records.pcap");
         tcps = tcps.stream().filter(t -> t.hasPayload()).collect(Collectors.toList());
 
@@ -26,6 +66,7 @@
 
         Iterator<Tcp> it = tcps.iterator();
         reqDecoder.decode(it.next().getPayload());
+        assertEquals(STATE_FINISHED, reqDecoder.state());
 
         respDecoder.decode(it.next().getPayload());
         assertEquals(STATE_DATA_NEEDED, respDecoder.state());
@@ -44,6 +85,26 @@
         assertEquals(1000, packets.stream().filter(p -> p instanceof MySqlRowResponse).count());
 
         reqDecoder.decode(it.next().getPayload());
+        assertEquals(STATE_FINISHED, reqDecoder.state());
+    }
 
+    @Test
+    public void testShowFieldsQuery() {
+        List<Tcp> tcps = PcapUtils.readTcpPackets("pcap/mysql/mysql_show_fields_req_res.pcap");
+
+        MySqlDecoderContext context = new MySqlDecoderContext();
+        MySqlRequestDecoder reqDecoder = new MySqlRequestDecoder(context);
+        MySqlResponsePacketsDecoder respDecoder = new MySqlResponsePacketsDecoder(context);
+
+        Iterator<Tcp> it = tcps.iterator();
+        reqDecoder.decode(it.next().getPayload());
+        assertEquals(STATE_FINISHED, reqDecoder.state());
+
+        respDecoder.decode(it.next().getPayload());
+        assertEquals(STATE_FINISHED, respDecoder.state());
+
+        List<MySqlPacket> packets = respDecoder.getResult();
+        assertEquals(5, packets.size());
+        assertEquals(4, packets.stream().filter(p -> p instanceof MySqlColumnDefinition).count());
     }
 }
\ No newline at end of file
Binary file stress-tester/src/test/resources/pcap/mysql/mysql_greeting_login.pcap has changed
Binary file stress-tester/src/test/resources/pcap/mysql/mysql_select_db_query.pcap has changed
Binary file stress-tester/src/test/resources/pcap/mysql/mysql_show_fields_req_res.pcap has changed
Binary file stress-tester/src/test/resources/pcap/mysql/mysql_use_db.pcap has changed