From: Kris Jurka Date: Tue, 3 Feb 2004 05:43:24 +0000 (+0000) Subject: V3 NotificationResonse messages were trying to be received as V2 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=34771fa703df18d5c02d0a024266ca68bcbbb3f3;p=users%2Fbernd%2Fpostgres.git V3 NotificationResonse messages were trying to be received as V2 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. --- diff --git a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java index 56a6b8a8f3..166949309a 100644 --- a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java +++ b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java @@ -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; //------------------------------ diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java index e1b480a1f1..3eab8e6633 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/Jdbc2TestSuite.java @@ -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 index 0000000000..0871885115 --- /dev/null +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/NotifyTest.java @@ -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(); + } +}