18
18
19
19
package org .apache .cassandra .distributed .test .cql3 ;
20
20
21
+ import java .net .Inet6Address ;
21
22
import java .net .InetAddress ;
23
+ import java .net .UnknownHostException ;
22
24
import javax .annotation .Nullable ;
23
25
24
26
import accord .utils .Property ;
31
33
import org .apache .cassandra .utils .FastByteOperations ;
32
34
import org .apache .cassandra .utils .Generators ;
33
35
import org .quicktheories .core .Gen ;
36
+ import org .quicktheories .generators .SourceDSL ;
34
37
35
38
public class InetSingleNodeTableWalkTest extends SingleNodeTableWalkTest
36
39
{
@@ -54,9 +57,7 @@ protected void preCheck(Property.StatefulBuilder builder)
54
57
{
55
58
// if a failing seed is detected, populate here
56
59
// Example: builder.withSeed(42L);
57
- // builder.withSeed(3985593186746556237L);
58
-
59
- builder .withSeed (-7293505339069640960L ); // ipv6 allow fitering missing partition
60
+ builder .withSeed (3985593186746556237L );
60
61
}
61
62
62
63
@ Override
@@ -73,8 +74,8 @@ private enum Mode { ipv4, ipv6, mixed }
73
74
protected InetState createState (RandomSource rs , Cluster cluster )
74
75
{
75
76
// Mode mode = rs.pick(Mode.values());
76
- Mode mode = rs .pick (Mode .ipv4 , Mode .ipv6 );
77
- // Mode mode = Mode.mixed;
77
+ // Mode mode = rs.pick(Mode.ipv4, Mode.ipv6);
78
+ Mode mode = Mode .mixed ;
78
79
Gen <InetAddress > gen ;
79
80
switch (mode )
80
81
{
@@ -85,7 +86,21 @@ protected InetState createState(RandomSource rs, Cluster cluster)
85
86
gen = Generators .INET_6_ADDRESS_UNRESOLVED_GEN ;
86
87
break ;
87
88
case mixed :
88
- gen = Generators .INET_ADDRESS_UNRESOLVED_GEN ;
89
+ var bool = SourceDSL .booleans ().all ();
90
+ gen = rnd -> {
91
+ if (bool .generate (rnd )) return Generators .INET_6_ADDRESS_UNRESOLVED_GEN .generate (rnd );
92
+ InetAddress ipv4 = Generators .INET_4_ADDRESS_UNRESOLVED_GEN .generate (rnd );
93
+ // lets convert to ipv6
94
+ byte [] address = normalize (ipv4 .getAddress ());
95
+ try
96
+ {
97
+ return Inet6Address .getByAddress (null , address , -1 );
98
+ }
99
+ catch (UnknownHostException e )
100
+ {
101
+ throw new AssertionError (e );
102
+ }
103
+ };
89
104
break ;
90
105
default :
91
106
throw new UnsupportedOperationException (mode .name ());
@@ -113,4 +128,18 @@ public String toString()
113
128
return "Mode: " + mode + "\n " + super .toString ();
114
129
}
115
130
}
131
+
132
+ public static byte [] normalize (byte [] address )
133
+ {
134
+ if (address .length == 16 ) return address ;
135
+ // migrate ipv4 to ipv6
136
+ byte [] ipv6 = new byte [16 ];
137
+ ipv6 [10 ] = (byte )0xff ;
138
+ ipv6 [11 ] = (byte )0xff ;
139
+ ipv6 [12 ] = address [0 ];
140
+ ipv6 [13 ] = address [1 ];
141
+ ipv6 [14 ] = address [2 ];
142
+ ipv6 [15 ] = address [3 ];
143
+ return ipv6 ;
144
+ }
116
145
}
0 commit comments