V3 NotificationResonse messages were trying to be received as V2
authorKris Jurka <books@ejurka.com>
Tue, 3 Feb 2004 05:43:24 +0000 (05:43 +0000)
committerKris Jurka <books@ejurka.com>
Tue, 3 Feb 2004 05:43:24 +0000 (05:43 +0000)
messages.  Also the PID was being read in the wrong byte order.
Finally add a test case for listen/notify.

Per report from Hans Nather.

src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java
src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
src/interfaces/jdbc/org/postgresql/test/jdbc2/NotifyTest.java [new file with mode: 0644]

index 56a6b8a8f340f1183ae98aafd8c895fc2da60f0c..166949309a2eed400935ece5da0b915f3335d96a 100644 (file)
@@ -118,8 +118,10 @@ public class Fastpath
                                switch (c)
                                {
                                        case 'A':       // Asynchronous Notify
-                                               int pid = stream.ReceiveInteger(4);
+                                               int msglen = stream.ReceiveIntegerR(4);
+                                               int pid = stream.ReceiveIntegerR(4);
                                                String msg = stream.ReceiveString(conn.getEncoding());
+                                               String param = stream.ReceiveString(conn.getEncoding());
                                                conn.addNotification(new org.postgresql.core.Notification(msg, pid));
                                                break;
                                                //------------------------------
@@ -233,8 +235,9 @@ public class Fastpath
                                {
                                        case 'A':       // Asynchronous Notify
                                                //TODO: do something with this
-                                               int pid = stream.ReceiveInteger(4);
+                                               int pid = stream.ReceiveIntegerR(4);
                                                String msg = stream.ReceiveString(conn.getEncoding());
+                                               conn.addNotification(new org.postgresql.core.Notification(msg, pid));
                                                break;
 
                                                //------------------------------
index e1b480a1f1c168fb1a340d7323035b6eb8760efa..3eab8e6633812eedb46c0a0b11629a4e41bf2b5e 100644 (file)
@@ -55,6 +55,7 @@ public class Jdbc2TestSuite extends TestSuite
                // features some applications require.
                suite.addTestSuite(JBuilderTest.class);
                suite.addTestSuite(MiscTest.class);
+               suite.addTestSuite(NotifyTest.class);
 
                // Fastpath/LargeObject
                suite.addTestSuite(BlobTest.class);
diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/NotifyTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/NotifyTest.java
new file mode 100644 (file)
index 0000000..0871885
--- /dev/null
@@ -0,0 +1,43 @@
+package org.postgresql.test.jdbc2;
+
+import org.postgresql.test.TestUtil;
+import junit.framework.TestCase;
+import java.sql.*;
+
+import org.postgresql.PGConnection;
+import org.postgresql.PGNotification;
+
+public class NotifyTest extends TestCase
+{
+
+       private Connection conn;
+
+       public NotifyTest(String name)
+       {
+               super(name);
+       }
+
+       protected void setUp() throws SQLException
+       {
+               conn = TestUtil.openDB();
+       }
+
+       protected void tearDown() throws SQLException
+       {
+               TestUtil.closeDB(conn);
+       }
+
+       public void testNotify() throws SQLException
+       {
+               Statement stmt = conn.createStatement();
+               stmt.executeUpdate("LISTEN mynotification");
+               stmt.executeUpdate("NOTIFY mynotification");
+
+               PGNotification notifications[] = ((org.postgresql.PGConnection)conn).getNotifications();
+               assertNotNull(notifications);
+               assertEquals(notifications.length, 1);
+               assertEquals(notifications[0].getName(), "mynotification");
+
+               stmt.close();
+       }
+}