22
22
*
23
23
24
24
/* @test
25
- * @bug 8014499
25
+ * @bug 8014499 8219804
26
26
* @summary Test for interference when two sockets are bound to the same
27
27
* port but joined to different multicast groups
28
28
* @run main Promiscuous
@@ -42,11 +42,20 @@ static void receive(MulticastSocket mc, boolean datagramExpected, int id)
42
42
throws IOException
43
43
{
44
44
byte [] ba = new byte [100 ];
45
- DatagramPacket p = new DatagramPacket ( ba , ba . length ) ;
45
+ DatagramPacket p ;
46
46
try {
47
- mc .receive (p );
48
- int recvId = Integer .parseInt (
49
- new String (p .getData (), 0 , p .getLength (), "UTF-8" ));
47
+ String data = null ;
48
+ while (true ) {
49
+ p = new DatagramPacket (ba , ba .length );
50
+ mc .receive (p );
51
+ data = new String (p .getData (), 0 , p .getLength (), "UTF-8" );
52
+ if (data .length () > UUID .length () && data .startsWith (UUID )) {
53
+ data = data .substring (UUID .length ());
54
+ break ;
55
+ }
56
+ logUnexpected (p );
57
+ }
58
+ int recvId = Integer .parseInt (data );
50
59
if (datagramExpected ) {
51
60
if (recvId != id )
52
61
throw new RuntimeException ("Unexpected id, got " + recvId
@@ -65,6 +74,20 @@ static void receive(MulticastSocket mc, boolean datagramExpected, int id)
65
74
}
66
75
}
67
76
77
+ static void logUnexpected (DatagramPacket p ) {
78
+ byte [] ba = p .getData ();
79
+ System .out .printf ("Unexpected packet: length: %d. First three bytes: %d, %d, %d\n " ,
80
+ p .getLength (), ba [0 ], ba [1 ], ba [2 ]);
81
+ }
82
+
83
+ static final String UUID ; // process-id : currentTimeMillis
84
+
85
+ static {
86
+ String s1 = Long .toString (ProcessHandle .current ().pid ());
87
+ String s2 = Long .toString (System .currentTimeMillis ());
88
+ UUID = "<" + s1 + s2 + ">" ;
89
+ }
90
+
68
91
static void test (InetAddress group1 , InetAddress group2 )
69
92
throws IOException
70
93
{
@@ -77,7 +100,7 @@ static void test(InetAddress group1, InetAddress group2)
77
100
mc1 .setSoTimeout (TIMEOUT );
78
101
mc2 .setSoTimeout (TIMEOUT );
79
102
int nextId = id ;
80
- byte [] msg = Integer .toString (nextId ).getBytes ("UTF-8" );
103
+ byte [] msg = ( UUID + Integer .toString (nextId ) ).getBytes ("UTF-8" );
81
104
DatagramPacket p = new DatagramPacket (msg , msg .length );
82
105
p .setAddress (group1 );
83
106
p .setPort (port );
@@ -95,7 +118,7 @@ static void test(InetAddress group1, InetAddress group2)
95
118
receive (mc2 , false , 0 );
96
119
97
120
nextId = ++id ;
98
- msg = Integer .toString (nextId ).getBytes ("UTF-8" );
121
+ msg = ( UUID + Integer .toString (nextId ) ).getBytes ("UTF-8" );
99
122
p = new DatagramPacket (msg , msg .length );
100
123
p .setAddress (group2 );
101
124
p .setPort (port );
@@ -129,8 +152,8 @@ public static void main(String args[]) throws IOException {
129
152
}
130
153
131
154
// multicast groups used for the test
132
- InetAddress ip4Group1 = InetAddress .getByName ("224.7.8.9 " );
133
- InetAddress ip4Group2 = InetAddress .getByName ("225.4.5.6 " );
155
+ InetAddress ip4Group1 = InetAddress .getByName ("224.0.0.120 " );
156
+ InetAddress ip4Group2 = InetAddress .getByName ("224.0.0.121 " );
134
157
135
158
test (ip4Group1 , ip4Group2 );
136
159
}
0 commit comments