|
60 | 60 | import org.apache.pulsar.client.api.ProducerBuilder; |
61 | 61 | import org.apache.pulsar.client.api.PulsarClientException; |
62 | 62 | import org.apache.pulsar.client.api.Reader; |
| 63 | +import org.apache.pulsar.client.api.Schema; |
63 | 64 | import org.apache.pulsar.client.api.SubscriptionInitialPosition; |
64 | | -import org.apache.pulsar.client.impl.schema.JSONSchema; |
65 | 65 | import org.apache.pulsar.common.policies.data.ClusterData; |
66 | 66 | import org.apache.pulsar.common.policies.data.PersistentTopicInternalStats; |
67 | 67 | import org.apache.pulsar.common.policies.data.RetentionPolicies; |
|
78 | 78 | public class ServiceUnitStateCompactionTest extends MockedPulsarServiceBaseTest { |
79 | 79 | private ScheduledExecutorService compactionScheduler; |
80 | 80 | private BookKeeper bk; |
81 | | - private JSONSchema<ServiceUnitStateData> schema; |
| 81 | + private Schema<ServiceUnitStateData> schema; |
82 | 82 | private ServiceUnitStateCompactionStrategy strategy; |
83 | 83 |
|
84 | 84 | private ServiceUnitState testState0 = Free; |
@@ -132,7 +132,6 @@ private ServiceUnitState nextValidState(ServiceUnitState from) { |
132 | 132 | .filter(to -> to != Free && to != Splitting && isValidTransition(from, to)) |
133 | 133 | .collect(Collectors.toList()); |
134 | 134 | var state= candidates.get(RANDOM.nextInt(candidates.size())); |
135 | | - System.out.println("test state:" + state); |
136 | 135 | return state; |
137 | 136 | } |
138 | 137 |
|
@@ -171,7 +170,7 @@ public void setup() throws Exception { |
171 | 170 | compactionScheduler = Executors.newSingleThreadScheduledExecutor( |
172 | 171 | new ThreadFactoryBuilder().setNameFormat("compaction-%d").setDaemon(true).build()); |
173 | 172 | bk = pulsar.getBookKeeperClientFactory().create(this.conf, null, null, Optional.empty(), null); |
174 | | - schema = JSONSchema.of(ServiceUnitStateData.class); |
| 173 | + schema = Schema.JSON(ServiceUnitStateData.class); |
175 | 174 | strategy = new ServiceUnitStateCompactionStrategy(); |
176 | 175 | strategy.checkBrokers(false); |
177 | 176 |
|
@@ -222,13 +221,12 @@ TestData generateTestData() throws PulsarAdminException, PulsarClientException { |
222 | 221 | for (int j = 0; j < numMessages; j++) { |
223 | 222 | int keyIndex = r.nextInt(maxKeys); |
224 | 223 | String key = "key" + keyIndex; |
225 | | - ServiceUnitStateData expectedData = expected.get(key); |
226 | | - ServiceUnitState state = expectedData == null ? nextValidState(Assigned) : |
227 | | - r.nextInt(2) == 0 ? nextInvalidState(expectedData.state()) : |
228 | | - nextValidState(expectedData.state()); |
| 224 | + ServiceUnitStateData prev = expected.get(key); |
| 225 | + ServiceUnitState prevState = prev == null ? Free : prev.state(); |
| 226 | + ServiceUnitState state = r.nextBoolean() ? nextInvalidState(prevState) : |
| 227 | + nextValidState(prevState); |
229 | 228 | ServiceUnitStateData value = new ServiceUnitStateData(state, key + ":" + j); |
230 | 229 | producer.newMessage().key(key).value(value).send(); |
231 | | - ServiceUnitStateData prev = expected.get(key); |
232 | 230 | if (!strategy.shouldKeepLeft(prev, value)) { |
233 | 231 | expected.put(key, value); |
234 | 232 | } |
|
0 commit comments