muttakin2301/ccr2000 huggingface dataset:
Code review comment: You should use the count down latch to increase contention.

Code under review:
public void testConcurrentSamples() throws Exception {
    VarIntCoder coder = VarIntCoder.of();
    OutputSampler<Integer> outputSampler = new OutputSampler<>(coder, 100000, 1);

    
    
    Thread sampleThreadA =
        new Thread(
            () -> {
              for (int i = 0; i < 10000000; i++) {
                outputSampler.sample(i);
              }
            });

    Thread sampleThreadB =
        new Thread(
            () -> {
              for (int i = 0; i < 10000000; i++) {
                outputSampler.sample(i);
              }
            });

    sampleThreadA.start();
    sampleThreadB.start();

    for (int i = 0; i < 10000; i++) {
      outputSampler.samples();
    }
  }

Line commented on: Thread sampleThreadA =

Revised code:
public void testConcurrentSamples() throws Exception {
    VarIntCoder coder = VarIntCoder.of();
    OutputSampler<Integer> outputSampler = new OutputSampler<>(coder, 10, 2);

    CountDownLatch startSignal = new CountDownLatch(1);
    CountDownLatch doneSignal = new CountDownLatch(2);

    
    
    
    Thread sampleThreadA =
        new Thread(
            () -> {
              try {
                startSignal.await();
              } catch (InterruptedException e) {
                return;
              }

              for (int i = 0; i < 1000000; i++) {
                outputSampler.sample(i);
              }

              doneSignal.countDown();
            });

    
    Thread sampleThreadB =
        new Thread(
            () -> {
              try {
                startSignal.await();
              } catch (InterruptedException e) {
                return;
              }

              for (int i = -1000000; i < 0; i++) {
                outputSampler.sample(i);
              }

              doneSignal.countDown();
            });

    
    sampleThreadA.start();
    sampleThreadB.start();

    
    startSignal.countDown();

    
    List<BeamFnApi.SampledElement> samples = new ArrayList<>();
    while (doneSignal.getCount() > 0) {
      samples.addAll(outputSampler.samples());
    }

    
    sampleThreadA.join();
    sampleThreadB.join();
    List<Integer> samplesFromThreadA = new ArrayList<>();
    List<Integer> samplesFromThreadB = new ArrayList<>();
    for (BeamFnApi.SampledElement sampledElement : samples) {
      int el = coder.decode(sampledElement.getElement().newInput());
      if (el >= 0) {
        samplesFromThreadA.add(el);
      } else {
        samplesFromThreadB.add(el);
      }
    }

    
    List<Integer> sortedSamplesFromThreadA = new ArrayList<>(samplesFromThreadA);
    List<Integer> sortedSamplesFromThreadB = new ArrayList<>(samplesFromThreadB);
    Collections.sort(sortedSamplesFromThreadA);
    Collections.sort(sortedSamplesFromThreadB);

    
    
    assertEquals(samplesFromThreadA, sortedSamplesFromThreadA);
    assertEquals(samplesFromThreadB, sortedSamplesFromThreadB);
  }
Code review comment: all `valueOf` methods: default should just return "unknown" so the API doesn't break if we add types.

Code under review:
private static String valueOf(Node.ClusterType type) {
        switch (type) {
            case admin: return "admin";
            case content: return "content";
            case container: return "container";
            default: throw new IllegalArgumentException("Unexpected node cluster type '" + type + "'.");
        }
    }

Line commented on: default: throw new IllegalArgumentException("Unexpected node cluster type '" + type + "'.");

Revised code:
private static String valueOf(Node.ClusterType type) {
        switch (type) {
            case admin: return "admin";
            case content: return "content";
            case container: return "container";
            default: throw new IllegalArgumentException("Unexpected node cluster type '" + type + "'.");
        }
    }
Code review comment: @yrodiere @Sanne could one of you have a look at this part? It changes how persistence units are started.

Code under review:
void startAll() {
        List<CompletableFuture<?>> start = new ArrayList<>();
        
        
        
        
        
        for (Map.Entry<String, LazyPersistenceUnit> i : persistenceUnits.entrySet()) {
            CompletableFuture<Object> future = new CompletableFuture<>();
            start.add(future);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        i.getValue().get();
                        future.complete(null);
                    } catch (Throwable t) {
                        future.completeExceptionally(t);
                    }
                }
            }, "JPA Startup Thread: " + i.getKey()).start();
        }
        for (CompletableFuture<?> i : start) {
            try {
                i.get();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
                throw new RuntimeException(e.getCause());
            }
        }
    }

Line commented on: List<CompletableFuture<?>> start = new ArrayList<>();

Revised code:
void startAll() {
        List<CompletableFuture<?>> start = new ArrayList<>();
        
        
        
        
        
        for (Map.Entry<String, LazyPersistenceUnit> i : persistenceUnits.entrySet()) {
            CompletableFuture<Object> future = new CompletableFuture<>();
            start.add(future);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        i.getValue().get();
                        future.complete(null);
                    } catch (Throwable t) {
                        future.completeExceptionally(t);
                    }
                }
            }, "JPA Startup Thread: " + i.getKey()).start();
        }
        for (CompletableFuture<?> i : start) {
            try {
                i.get();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (ExecutionException e) {
                throw new RuntimeException(e.getCause());
            }
        }
    }
Code review comment: @samvaity - agreed, we can add nested / non-nested information on context always irrespective of the API if it doesn't result in a perf hit. Added it to this issue: https://github.com/Azure/azure-sdk-for-java/issues/13031

Code under review:
private CosmosPagedFlux<CosmosDatabaseProperties> queryDatabasesInternal(SqlQuerySpec querySpec, CosmosQueryRequestOptions options){
        return UtilBridgeInternal.createCosmosPagedFlux(pagedFluxOptions -> {
            pagedFluxOptions.setTracerInformation(this.tracerProvider, "queryDatabases", this.serviceEndpoint, null);
            setContinuationTokenAndMaxItemCount(pagedFluxOptions, options);
            return getDocClientWrapper().queryDatabases(querySpec, options)
                .map(response -> BridgeInternal.createFeedResponse(
                    ModelBridgeInternal.getCosmosDatabasePropertiesFromV2Results(response.getResults()),
                    response.getResponseHeaders()));
        });
    }

Line commented on: pagedFluxOptions.setTracerInformation(this.tracerProvider, "queryDatabases", this.serviceEndpoint, null);

Revised code:
private CosmosPagedFlux<CosmosDatabaseProperties> queryDatabasesInternal(SqlQuerySpec querySpec, CosmosQueryRequestOptions options){
        return UtilBridgeInternal.createCosmosPagedFlux(pagedFluxOptions -> {
            pagedFluxOptions.setTracerInformation(this.tracerProvider, "queryDatabases", this.serviceEndpoint, null);
            setContinuationTokenAndMaxItemCount(pagedFluxOptions, options);
            return getDocClientWrapper().queryDatabases(querySpec, options)
                .map(response -> BridgeInternal.createFeedResponse(
                    ModelBridgeInternal.getCosmosDatabasePropertiesFromV2Results(response.getResults()),
                    response.getResponseHeaders()));
        });
    }
Code review comment: Decreasing parallelism just a little bit would cover more cases, WDYT?  i.e. ```suggestion         int scaledDownParallelism = PARALLELISM - 1; ```

Code under review:
void testRequirementDecreaseTriggersScaleDown() throws Exception {
        final JobGraph jobGraph = createJobGraph();

        final DefaultDeclarativeSlotPool declarativeSlotPool =
                createDeclarativeSlotPool(jobGraph.getJobID());

        final Configuration configuration = new Configuration();
        configuration.set(JobManagerOptions.RESOURCE_WAIT_TIMEOUT, Duration.ofMillis(1L));

        final AdaptiveScheduler scheduler =
                new AdaptiveSchedulerBuilder(jobGraph, singleThreadMainThreadExecutor)
                        .setDeclarativeSlotPool(declarativeSlotPool)
                        .setJobMasterConfiguration(configuration)
                        .build(EXECUTOR_RESOURCE.getExecutor());

        final SubmissionBufferingTaskManagerGateway taskManagerGateway =
                createSubmissionBufferingTaskManagerGateway(PARALLELISM, scheduler);

        startJobWithSlotsMatchingParallelism(
                scheduler, declarativeSlotPool, taskManagerGateway, PARALLELISM);
        awaitJobReachingParallelism(taskManagerGateway, scheduler, PARALLELISM);

        int scaledDownParallelism = PARALLELISM / 2;
        JobResourceRequirements newJobResourceRequirements =
                createRequirementsWithUpperParallelism(scaledDownParallelism);
        singleThreadMainThreadExecutor.execute(
                () -> scheduler.updateJobResourceRequirements(newJobResourceRequirements));

        awaitJobReachingParallelism(taskManagerGateway, scheduler, scaledDownParallelism);
    }

Line commented on: int scaledDownParallelism = PARALLELISM / 2;

Revised code:
void testRequirementDecreaseTriggersScaleDown() throws Exception {
        final JobGraph jobGraph = createJobGraph();

        final DefaultDeclarativeSlotPool declarativeSlotPool =
                createDeclarativeSlotPool(jobGraph.getJobID());

        final AdaptiveScheduler scheduler =
                createSchedulerWithNoResourceWaitTimeout(jobGraph, declarativeSlotPool);

        final SubmissionBufferingTaskManagerGateway taskManagerGateway =
                createSubmissionBufferingTaskManagerGateway(PARALLELISM, scheduler);

        startJobWithSlotsMatchingParallelism(
                scheduler, declarativeSlotPool, taskManagerGateway, PARALLELISM);
        awaitJobReachingParallelism(taskManagerGateway, scheduler, PARALLELISM);

        int scaledDownParallelism = PARALLELISM - 1;
        JobResourceRequirements newJobResourceRequirements =
                createRequirementsWithUpperParallelism(scaledDownParallelism);
        singleThreadMainThreadExecutor.execute(
                () -> scheduler.updateJobResourceRequirements(newJobResourceRequirements));

        awaitJobReachingParallelism(taskManagerGateway, scheduler, scaledDownParallelism);
    }
Code review comment: You are correct that this was not correct, especially also on partially completed tasks.  I changed it to regular state and let the committer handle duplicates now. The main idea is to avoid extra transactions as much as possible in the writer and if it's not possible, let the committer clean them up anyhow.

Code under review:
public void endInput() throws Exception {
        if (!this.endOfInput) {
            this.endOfInput = true;
            
            if (getRuntimeContext().getTaskInfo().getIndexOfThisSubtask() == 0) {
                endOfInputState.add(true);
            }
            sinkWriter.flush(true);
            emitCommittables(Long.MAX_VALUE);
        }
    }


Revised code:
public void endInput() throws Exception {
        if (!endOfInput) {
            endOfInput = true;
            if (endOfInputState != null) {
                endOfInputState.add(true);
            }
            sinkWriter.flush(true);
            emitCommittables(CommittableMessage.EOI);
        }
    }
Code review comment: Whether it is in the name or not, I think is a secondary issue. If we provide some stats, it's best if all have the same units.  https://ci.apache.org/projects/flink/flink-docs-stable/monitoring/metrics.html#checkpointing  however, annoying thing is, that in this class yes, all units are in nanos, but in other places it's millis (7 metrics in millis vs 2 in nanos?). More over, web ui is also using millis only...

Code under review:
protected void markCheckpointStart(long checkpointCreationTimestamp) {
		latestCheckpointStartDelayNanos = 1000_000 * Math.max(
			0,
			System.currentTimeMillis() - checkpointCreationTimestamp);
	}

Line commented on: latestCheckpointStartDelayNanos = 1000_000 * Math.max(

Revised code:
protected void markCheckpointStart(long checkpointCreationTimestamp) {
		latestCheckpointStartDelayNanos = 1_000_000 * Math.max(
			0,
			System.currentTimeMillis() - checkpointCreationTimestamp);
	}
Code review comment: The code you pasted is not the latest. The `fillDisableDictOptimizeColumns(v, columnRefSet, sids)` function just check if the operator can be optimized, if not it union these cols just like code in line#127. So if we have done the union operation before, the further check is unnecessary.

Code under review:
public void fillDisableDictOptimizeColumns(ColumnRefSet columnRefSet, Set<Integer> sids) {
        columnRefMap.forEach((k, v) -> {
            if (columnRefSet.contains(k.getId())) {
                columnRefSet.union(v.getUsedColumns());
            } else {
                fillDisableDictOptimizeColumns(v, columnRefSet, sids);
            }
        });
    }

Line commented on: fillDisableDictOptimizeColumns(v, columnRefSet, sids);

Revised code:
public void fillDisableDictOptimizeColumns(ColumnRefSet columnRefSet, Set<Integer> sids) {
        columnRefMap.forEach((k, v) -> {
            if (columnRefSet.contains(k.getId())) {
                columnRefSet.union(v.getUsedColumns());
            } else {
                fillDisableDictOptimizeColumns(v, columnRefSet, sids);
            }
        });
    }
Code review comment: And yes, you need that many backslashes :]

Code under review:
private static String escapeXrefTitleForReplaceAll(String title) {
        return title.trim().replace("]", "\\\\]");
    }

Line commented on: return title.trim().replace("]", "\\\\]");

Revised code:
private static String escapeXrefTitleForReplaceAll(String title) {
        return title.trim().replace("]", "\\\\]");
    }
Code review comment: That's true. Reverted to former implementation due to using ArrayList, see comment elsewhere.

Code under review:
private void deleteLines(int startIndex, int endIndex) {
        for (int i = startIndex; i < endIndex; ++i) {
            lines.remove(startIndex);
        }
    }

Line commented on: lines.remove(startIndex);

Revised code:
private void deleteLines(int startIndex, int endIndex) {
        for (int fromIndex = endIndex, toIndex = startIndex; fromIndex <= getMaxLineIndex();
             ++toIndex, ++fromIndex) {
            lines.set(toIndex, lines.get(fromIndex));
        }

        truncate(getMaxLineIndex() - (endIndex - startIndex));
    }
Code review comment: Dont you need ":port" as well when configserverConfig.zookeeperLocalhostAffinity()  is true?

Code under review:
private Curator(ConfigserverConfig configserverConfig, String zooKeeperEnsembleConnectionSpec) {
        this(configserverConfig.zookeeperLocalhostAffinity() ?
                HostName.getLocalhost() : zooKeeperEnsembleConnectionSpec,
                zooKeeperEnsembleConnectionSpec);
    }

Line commented on: HostName.getLocalhost() : zooKeeperEnsembleConnectionSpec,

Revised code:
private Curator(ConfigserverConfig configserverConfig, String zooKeeperEnsembleConnectionSpec) {
        this(configserverConfig.zookeeperLocalhostAffinity() ?
                createConnectionSpecForLocalhost(configserverConfig) : zooKeeperEnsembleConnectionSpec,
                zooKeeperEnsembleConnectionSpec);
    }
Code review comment: >om", [](start = 18, length = 4)  We are making type mandatory in .net, can do the same here: [https://github.com/Azure/azure-cosmos-dotnet-v3/pull/2283](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/2283)

Code under review:
public EncryptionKeyWrapMetadata(String name, String value) {
        this("custom", name, value, null);
    }

Line commented on: this("custom", name, value, null);

Revised code:
public EncryptionKeyWrapMetadata(String name, String value) {
        this("custom", name, value, null);
    }
Code review comment: > quorumPeer.running should be set to false (under a synchronized(quorumPeer)), which means the quorumPeer thread will eventually exit its thread  `quorumPeer.running` is private though, as far as I can tell we can only initiate shutdown through `quorumPeer.shutdown()`  > wait until quorumPeer thread exits with quorumPeer.join(),  Yes, will fix.  > And (2) may happen a long time after we return from this method, meaning it may still run concurrently with trying to start another instance of ZK.  Yes, there any many reasons that the old server will linger. Component destruction only happens after 60s for example. This is why server start is retried.

Code under review:
public void shutdown() {
        if (quorumPeer != null) {
            try {
                quorumPeer.shutdown();
            } catch (RuntimeException e) {
                
                
                
                
                
                
                LOG.log(Level.SEVERE, "Failed to shut down properly, forcing restart", e);
                System.exit(1);
            }
        }
    }

Line commented on: quorumPeer.shutdown();

Revised code:
public void shutdown() {
        if (quorumPeer != null) {
            try {
                quorumPeer.shutdown();
            } catch (RuntimeException e) {
                
                
                
                
                
                
                LOG.log(Level.SEVERE, "Failed to shut down properly, forcing restart", e);
                System.exit(1);
            }
        }
    }
Code review comment: I see. Thanks for spotting this!

Code under review:
public void test() {
        get("/ping?val=bar").then().statusCode(200).body(is("foo_bar"));
        assertTrue(Ping.DESTROYED.get());
    }

Line commented on: assertTrue(Ping.DESTROYED.get());

Revised code:
public void test() throws InterruptedException, ExecutionException, TimeoutException {
        get("/ping?val=bar").then().statusCode(200).body(is("foo_bar"));
        assertTrue(Ping.DESTROYED.get(2, TimeUnit.SECONDS));
    }
Code review comment: @xinyuiscool is this issue something that affects you or that you have noticed?

Code under review:
public static void convertReadBasedSplittableDoFnsToPrimitiveReadsIfNecessary(Pipeline pipeline) {
    if (!ExperimentalOptions.hasExperiment(pipeline.getOptions(), "use_sdf_read")
        || ExperimentalOptions.hasExperiment(
            pipeline.getOptions(), "beam_fn_api_use_deprecated_read")
        || ExperimentalOptions.hasExperiment(pipeline.getOptions(), "use_deprecated_read")) {
      convertReadBasedSplittableDoFnsToPrimitiveReads(pipeline);
    }
  }

Line commented on: if (!ExperimentalOptions.hasExperiment(pipeline.getOptions(), "use_sdf_read")

Revised code:
public static void convertReadBasedSplittableDoFnsToPrimitiveReadsIfNecessary(Pipeline pipeline) {
    if (!ExperimentalOptions.hasExperiment(pipeline.getOptions(), "use_sdf_read")
        || ExperimentalOptions.hasExperiment(
            pipeline.getOptions(), "beam_fn_api_use_deprecated_read")
        || ExperimentalOptions.hasExperiment(pipeline.getOptions(), "use_deprecated_read")) {
      convertReadBasedSplittableDoFnsToPrimitiveReads(pipeline);
    }
  }
Code review comment: Agree that we don't need this. Preserving the order per application is sufficient.

Code under review:
public void setRoutingStatus(ZoneId zone, RoutingStatus.Value value) {
        try (var lock = db.lockRoutingPolicies()) {
            db.writeZoneRoutingPolicy(new ZoneRoutingPolicy(zone, RoutingStatus.create(value, RoutingStatus.Agent.operator,
                                                                                       controller.clock().instant())));
            Map<ApplicationId, RoutingPolicyList> allPolicies = readAll().groupingBy(policy -> policy.id().owner());
            for (var instancePolicies : allPolicies.values()) {
                updateGlobalDnsOf(instancePolicies, Set.of(), Optional.empty(), lock);
            }
        }
    }

Line commented on: updateGlobalDnsOf(instancePolicies, Set.of(), Optional.empty(), lock);

Revised code:
public void setRoutingStatus(ZoneId zone, RoutingStatus.Value value) {
        try (var lock = db.lockRoutingPolicies()) {
            db.writeZoneRoutingPolicy(new ZoneRoutingPolicy(zone, RoutingStatus.create(value, RoutingStatus.Agent.operator,
                                                                                       controller.clock().instant())));
            Map<ApplicationId, RoutingPolicyList> allPolicies = readAll().groupingBy(policy -> policy.id().owner());
            allPolicies.forEach((instance, policies) -> {
                updateGlobalDnsOf(policies, Set.of(), Optional.of(TenantAndApplicationId.from(instance)), lock);
            });
        }
    }
Code review comment: I would say that I wouldn't import a Google class just for that. So I would remove it for now and revisit if the changes you made are not stable enough.

Code under review:
void createMultipleTimes() throws InterruptedException {
        final ExecutorService executorService = Executors.newFixedThreadPool(4);
        final CountDownLatch latch = new CountDownLatch(20);
        final Stopwatch watch = Stopwatch.createStarted();
        Map<String, Object> properties = new HashMap<>();
        properties.put("extensions", "commons-io:commons-io:2.5");

        List<Callable<Void>> collect = IntStream.range(0, 20).boxed().map(i -> (Callable<Void>) () -> {
            File tempDir = Files.createTempDirectory("test").toFile();
            FileProjectWriter write = new FileProjectWriter(tempDir);
            new CreateProject(write)
                    .groupId("org.acme")
                    .artifactId("acme")
                    .version("1.0.0-SNAPSHOT")
                    .className("org.acme.MyResource")
                    .doCreateProject(properties);
            latch.countDown();
            write.close();
            tempDir.delete();
            return null;
        }).collect(Collectors.toList());
        executorService.invokeAll(collect);
        latch.await();
        System.out.println(watch.toString());
    }

Line commented on: System.out.println(watch.toString());

Revised code:
void createMultipleTimes() throws InterruptedException {
        final ExecutorService executorService = Executors.newFixedThreadPool(4);
        final CountDownLatch latch = new CountDownLatch(20);
        Map<String, Object> properties = new HashMap<>();
        properties.put("extensions", "commons-io:commons-io:2.5");

        List<Callable<Void>> collect = IntStream.range(0, 20).boxed().map(i -> (Callable<Void>) () -> {
            File tempDir = Files.createTempDirectory("test").toFile();
            FileProjectWriter write = new FileProjectWriter(tempDir);
            new CreateProject(write)
                    .groupId("org.acme")
                    .artifactId("acme")
                    .version("1.0.0-SNAPSHOT")
                    .className("org.acme.MyResource")
                    .doCreateProject(properties);
            latch.countDown();
            write.close();
            tempDir.delete();
            return null;
        }).collect(Collectors.toList());
        executorService.invokeAll(collect);
        latch.await();
    }
Code review comment: The most risky bug in this code is: Using the `getType().isComplexType()` check and introducing the `isJsonType()` check without considering that a `Type` can be both complex and JSON.  You can modify the code like this: ```java // was if (variable.getType().isComplexType()) {  // now if (variable.getType().isComplexType() && !variable.getType().isJsonType()) { ``` This change ensures that variables that are of JSON type, which may or may not be considered complex depending on the implementation details of `isComplexType()` and `isJsonType()`, are correctly handled and not incorrectly filtered out if they should be accounted for as JSON types.

Code under review:
private Optional<AccessPath> process(ScalarOperator scalarOperator, Deque<AccessPath> accessPaths) {
            
            List<Optional<AccessPath>> childAccessPaths = scalarOperator.getChildren().stream()
                    .map(child -> process(child, accessPaths))
                    .collect(Collectors.toList());
            
            
            if (!childAccessPaths.isEmpty() && childAccessPaths.stream().noneMatch(Optional::isPresent)) {
                return Optional.empty();
            }
            Optional<AccessPath> currentPath = scalarOperator.accept(this, childAccessPaths);
            AccessPath path = currentPath.orElse(null);
            
            
            
            
            
            childAccessPaths.stream().filter(p -> p.isPresent() && p.get() != path)
                    .map(Optional::get).forEach(accessPaths::add);
            return currentPath;
        }

Line commented on: List<Optional<AccessPath>> childAccessPaths = scalarOperator.getChildren().stream()

Revised code:
private Optional<AccessPath> process(ScalarOperator scalarOperator, Deque<AccessPath> accessPaths) {
            
            List<Optional<AccessPath>> childAccessPaths = scalarOperator.getChildren().stream()
                    .map(child -> process(child, accessPaths))
                    .collect(Collectors.toList());
            
            
            if (!childAccessPaths.isEmpty() && childAccessPaths.stream().noneMatch(Optional::isPresent)) {
                return Optional.empty();
            }
            Optional<AccessPath> currentPath = scalarOperator.accept(this, childAccessPaths);
            AccessPath path = currentPath.orElse(null);
            
            
            
            
            
            childAccessPaths.stream().filter(p -> p.isPresent() && p.get() != path)
                    .map(Optional::get).forEach(accessPaths::add);
            return currentPath;
        }
Code review comment: You drop it because we don't care about it past that line right?

Code under review:
public static void manualInitialize() {
        int tmpState = manualState;
        if (tmpState == MANUAL_FAILURE)
            throw new RuntimeException("Quarkus manual bootstrap failed");
        if (tmpState > MANUAL_BEGIN)
            return;
        synchronized (manualLock) {
            tmpState = manualState;
            if (tmpState > MANUAL_BEGIN)
                return;
            if (tmpState == MANUAL_FAILURE)
                throw new RuntimeException("Quarkus manual bootstrap failed");
            manualState = MANUAL_BEGIN_INITIALIZATION;
        }

        try {
            
            
            Class<?> appClass = Class.forName("io.quarkus.runner.ApplicationImpl");
            manualApp = (Application) appClass.getDeclaredConstructor().newInstance();
            manualState = MANUAL_INITIALIZED;
            Core.getGlobalContext().register(new QuarkusCracBootstrapResource());
        } catch (Exception e) {
            manualState = MANUAL_FAILURE;
            throw new RuntimeException("Quarkus manual initialization failed", e);
        }
    }

Line commented on: manualState = MANUAL_BEGIN_INITIALIZATION;

Revised code:
public static void manualInitialize() {
        int tmpState = manualState;
        if (tmpState == MANUAL_FAILURE)
            throw new RuntimeException("Quarkus manual bootstrap failed");
        if (tmpState > MANUAL_BEGIN)
            return;
        synchronized (manualLock) {
            tmpState = manualState;
            if (tmpState > MANUAL_BEGIN)
                return;
            if (tmpState == MANUAL_FAILURE)
                throw new RuntimeException("Quarkus manual bootstrap failed");
            manualState = MANUAL_BEGIN_INITIALIZATION;
        }

        try {
            
            
            Class<?> appClass = Class.forName("io.quarkus.runner.ApplicationImpl");
            manualApp = (Application) appClass.getDeclaredConstructor().newInstance();
            manualState = MANUAL_INITIALIZED;
            Core.getGlobalContext().register(new QuarkusCracBootstrapResource());
        } catch (Exception e) {
            manualState = MANUAL_FAILURE;
            throw new RuntimeException("Quarkus manual initialization failed", e);
        }
    }
Code review comment: Yes, we can do that too.  Since this is implementation detail, will change it in next PR .

Code under review:
public static String decodeAsUTF8String(String inputString) {
        if (inputString == null || inputString.isEmpty()) {
            return inputString;
        }
        try {
            return URLDecoder.decode(inputString, StandardCharsets.UTF_8.toString());
        } catch (UnsupportedEncodingException e) {
            logger.warn("Error while decoding input string", e);
            return inputString;
        }
    }

Line commented on: if (inputString == null || inputString.isEmpty()) {

Revised code:
public static String decodeAsUTF8String(String inputString) {
        if (inputString == null || inputString.isEmpty()) {
            return inputString;
        }
        try {
            return URLDecoder.decode(inputString, StandardCharsets.UTF_8.toString());
        } catch (UnsupportedEncodingException e) {
            logger.warn("Error while decoding input string", e);
            return inputString;
        }
    }
Code review comment: Then I'll keep the implementation as is. If the user passes in a null options object, we will send the current timestamp for them

Code under review:
Mono<Response<Void>> publishTelemetryWithResponse(String digitalTwinId, String messageId, Object payload, DigitalTwinsSendTelemetryOptions options, Context context) {
        if (messageId == null || messageId.isEmpty()) {
            messageId = UUID.randomUUID().toString();
        }

        com.azure.digitaltwins.core.implementation.models.DigitalTwinsSendTelemetryOptions protocolLayerOptions;
        if (options == null) {
            options = new DigitalTwinsSendTelemetryOptions();
            protocolLayerOptions = null;
        }
        else {
            protocolLayerOptions = new com.azure.digitaltwins.core.implementation.models.DigitalTwinsSendTelemetryOptions()
                .setTraceparent(options.getTraceparent())
                .setTracestate(options.getTracestate());
        }

        return protocolLayer.getDigitalTwins().sendTelemetryWithResponseAsync(
            digitalTwinId,
            messageId,
            payload,
            options.getTimestamp().toString(),
            protocolLayerOptions,
            context);
    }

Line commented on: options.getTimestamp().toString(),

Revised code:
new DigitalTwinsSendTelemetryOptions();
            protocolLayerOptions = null;
        }
        else {
            protocolLayerOptions = new com.azure.digitaltwins.core.implementation.models.DigitalTwinsSendTelemetryOptions()
                .setTraceparent(options.getTraceparent())
                .setTracestate(options.getTracestate());
        }
Code review comment: Do you check whether the user specified partitions are all valid partitions?

Code under review:
private void updateCurrentKafkaPartitions() {
        if (customKafkaPartitions == null || customKafkaPartitions.size() == 0) {
            LOG.debug("All of partitions which belong to topic will be load for {} routine load job", name);
            
            currentKafkaPartitions.addAll(getAllKafkaPartitions());
        } else {
            currentKafkaPartitions = customKafkaPartitions;
        }
        for (Integer kafkaPartition : currentKafkaPartitions) {
            try {
                ((KafkaProgress) progress).getPartitionIdToOffset().get(kafkaPartition);
            } catch (NullPointerException e) {
                ((KafkaProgress) progress).getPartitionIdToOffset().put(kafkaPartition, 0L);
            }
        }
    }

Line commented on: currentKafkaPartitions = customKafkaPartitions;

Revised code:
private void updateCurrentKafkaPartitions() {
        if (customKafkaPartitions == null || customKafkaPartitions.size() == 0) {
            LOG.debug("All of partitions which belong to topic will be loaded for {} routine load job", name);
            
            currentKafkaPartitions.addAll(getAllKafkaPartitions());
        } else {
            currentKafkaPartitions = customKafkaPartitions;
        }
        
        for (Integer kafkaPartition : currentKafkaPartitions) {
            try {
                ((KafkaProgress) progress).getPartitionIdToOffset().get(kafkaPartition);
            } catch (NullPointerException e) {
                ((KafkaProgress) progress).getPartitionIdToOffset().put(kafkaPartition, 0L);
            }
        }
    }
Code review comment: "What if we need to set up/create an object on the service first (as part of the arrange), before acting on it? Do we initialize the sync client too, and use it to arrange the setup? Or do we use a multi…"  you can chain multiple service calls asynchronously through Reactor operators like then().. so, the first call will do the necessary setup on the service and then call the next method that you want to test

Code under review:
public void canGetExistingChatThread() {
        
        CreateChatThreadOptions threadRequest = ChatOptionsProvider.createThreadOptions(
            firstThreadMember.getId(), secondThreadMember.getId());
        ChatThreadAsyncClient chatThreadClient = client.createChatThread(threadRequest).block();

        
        StepVerifier.create(client.getChatThread(chatThreadClient.getChatThreadId()))
            .assertNext(chatThread -> {
                assertEquals(chatThreadClient.getChatThreadId(), chatThread.getId());
            })
            .verifyComplete();
    }

Line commented on: ChatThreadAsyncClient chatThreadClient = client.createChatThread(threadRequest).block();

Revised code:
public void canGetExistingChatThread() {
        
        CreateChatThreadOptions threadRequest = ChatOptionsProvider.createThreadOptions(
            firstThreadMember.getId(), secondThreadMember.getId());

        
        AtomicReference<ChatThreadAsyncClient> chatThreadClientRef = new AtomicReference<>();
        StepVerifier.create(
            client.createChatThread(threadRequest)
                .flatMap(chatThreadClient -> {
                    chatThreadClientRef.set(chatThreadClient);
                    return client.getChatThread(chatThreadClient.getChatThreadId());
                }))
            .assertNext(chatThread -> {
                assertEquals(chatThreadClientRef.get().getChatThreadId(), chatThread.getId());
            })
            .verifyComplete();
    }
Code review comment: Why does the outerSchema need to be nullable here?

Code under review:
public void testParameterStruct() {
    String sql = "SELECT @p as ColA";
    ImmutableMap<String, Value> params =
        ImmutableMap.of(
            "p",
            Value.createStructValue(
                TypeFactory.createStructType(
                    ImmutableList.of(
                        new StructType.StructField(
                            "s", TypeFactory.createSimpleType(TypeKind.TYPE_STRING)),
                        new StructType.StructField(
                            "i", TypeFactory.createSimpleType(TypeKind.TYPE_INT64)))),
                ImmutableList.of(Value.createStringValue("foo"), Value.createInt64Value(1L))));

    ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
    BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql, params);
    PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);

    final Schema innerSchema =
        Schema.of(Field.of("s", FieldType.STRING), Field.of("i", FieldType.INT64));
    final Schema schema =
        Schema.builder().addNullableField("field1", FieldType.row(innerSchema)).build();

    PAssert.that(stream)
        .containsInAnyOrder(
            Row.withSchema(schema)
                .addValue(Row.withSchema(innerSchema).addValues("foo", 1L).build())
                .build());

    pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
  }

Line commented on: Schema.builder().addNullableField("field1", FieldType.row(innerSchema)).build();

Revised code:
public void testParameterStruct() {
    String sql = "SELECT @p as ColA";
    ImmutableMap<String, Value> params =
        ImmutableMap.of(
            "p",
            Value.createStructValue(
                TypeFactory.createStructType(
                    ImmutableList.of(
                        new StructType.StructField(
                            "s", TypeFactory.createSimpleType(TypeKind.TYPE_STRING)),
                        new StructType.StructField(
                            "i", TypeFactory.createSimpleType(TypeKind.TYPE_INT64)))),
                ImmutableList.of(Value.createStringValue("foo"), Value.createInt64Value(1L))));

    ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
    BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql, params);
    PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);

    final Schema innerSchema =
        Schema.of(Field.of("s", FieldType.STRING), Field.of("i", FieldType.INT64));
    final Schema schema = Schema.of(Field.of("field1", FieldType.row(innerSchema)));

    PAssert.that(stream)
        .containsInAnyOrder(
            Row.withSchema(schema)
                .addValue(Row.withSchema(innerSchema).addValues("foo", 1L).build())
                .build());

    pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
  }
Code review comment: What would happened if `element == null`?

Code under review:
public void serialize(Set<T> set, DataOutputView target) throws IOException {
        final int size = set.size();
        target.writeInt(size);
        for (T element : set) {
            elementSerializer.serialize(element, target);
        }
    }

Line commented on: elementSerializer.serialize(element, target);

Revised code:
public void serialize(Set<T> set, DataOutputView target) throws IOException {
        final int size = set.size();
        target.writeInt(size);
        for (T element : set) {
            if (element == null) {
                target.writeBoolean(true);
            } else {
                target.writeBoolean(false);
                elementSerializer.serialize(element, target);
            }
        }
    }
Code review comment: @zentol  Thank you very much for the good catch. I'm so sorry for the rookie mistake. I'll check it carefully

Code under review:
void testNonCoordinationMode() throws Exception {
        assertThat(OperatingSystem.isLinux()).isTrue();
        testExistWithNonZero("test_non_coordination_mode");
    }

Line commented on: assertThat(OperatingSystem.isLinux()).isTrue();

Revised code:
void testNonCoordinationMode() throws Exception {
        assumeThat(OperatingSystem.isLinux()).isTrue();
        testExistWithNonZero("test_non_coordination_mode");
    }
Code review comment: Maybe it's a stupid question but you don't want to support the gzip providers in the REST client case?  It would probably be nice to support it too, no? I think what is done in the server part indeed also considers the client case so I would just put that code in resteasy-common. And this particular config item would be moved to the common part too.

Code under review:
public void register(RegistrationContext registrationContext) {
                for (Map.Entry<DotName, ClassInfo> entry : interfaces.entrySet()) {
                    BeanConfigurator<Object> configurator = registrationContext.configure(entry.getKey());
                    
                    configurator.addType(entry.getKey());
                    
                    configurator.scope(BuiltinScope.SINGLETON.getInfo());
                    configurator.addQualifier(REST_CLIENT);
                    configurator.creator(m -> {
                        
                        ResultHandle interfaceHandle = m.loadClass(entry.getKey().toString());
                        ResultHandle baseHandle = m.newInstance(
                                MethodDescriptor.ofConstructor(RestClientBase.class, Class.class), interfaceHandle);
                        ResultHandle ret = m.invokeVirtualMethod(
                                MethodDescriptor.ofMethod(RestClientBase.class, "create", Object.class), baseHandle);
                        m.returnValue(ret);
                    });
                    configurator.done();
                }
            }

Line commented on: m.returnValue(ret);

Revised code:
public void register(RegistrationContext registrationContext) {
                for (Map.Entry<DotName, ClassInfo> entry : interfaces.entrySet()) {
                    BeanConfigurator<Object> configurator = registrationContext.configure(entry.getKey());
                    
                    configurator.addType(entry.getKey());
                    
                    configurator.scope(BuiltinScope.SINGLETON.getInfo());
                    configurator.addQualifier(REST_CLIENT);
                    configurator.creator(m -> {
                        
                        ResultHandle interfaceHandle = m.loadClass(entry.getKey().toString());
                        ResultHandle baseHandle = m.newInstance(
                                MethodDescriptor.ofConstructor(RestClientBase.class, Class.class), interfaceHandle);
                        ResultHandle ret = m.invokeVirtualMethod(
                                MethodDescriptor.ofMethod(RestClientBase.class, "create", Object.class), baseHandle);
                        m.returnValue(ret);
                    });
                    configurator.done();
                }
            }
Code review comment: Surprisingly, it turns out the service actually will accept `x-ms-client-request-id` if `client-request-id` is not provided. This must be a case of the service having changed after this part of the Track 1 .NET SDK was written.  We can remove this special case whenever is convenient (perhaps before GA).

Code under review:
public SearchIndexAsyncClient buildAsyncClient() {

        policies.add(new AddHeadersPolicy(headers));
        
        
        policies.add(new RequestIdPolicy("client-request-id"));
        policies.add(new AddDatePolicy());
        HttpPolicyProviders.addBeforeRetryPolicies(policies);
        policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy);
        HttpPolicyProviders.addAfterRetryPolicies(policies);

        return new SearchIndexAsyncClient(endpoint, indexName, apiVersion, prepareForBuildClient());
    }

Line commented on: policies.add(new RequestIdPolicy("client-request-id"));

Revised code:
public SearchIndexAsyncClient buildAsyncClient() {

        policies.add(new AddHeadersPolicy(headers));
        
        
        policies.add(new RequestIdPolicy("client-request-id"));
        policies.add(new AddDatePolicy());
        HttpPolicyProviders.addBeforeRetryPolicies(policies);
        policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy);
        HttpPolicyProviders.addAfterRetryPolicies(policies);

        return new SearchIndexAsyncClient(endpoint, indexName, apiVersion, prepareForBuildClient());
    }
Code review comment: yes, I think we should remove those, I had similar thought a few weeks ago but got distracted from opening PR 😓: https://github.com/trask/azure-sdk-for-java/commit/af44c693a9e4bbf1013857ec34724a3412216d0f

Code under review:
private void end(int statusCode, Throwable throwable, Context context) {
        if (throwable != null) {
            if (statusCode == HttpConstants.StatusCodes.NOTFOUND) {
                tracer.setAttribute(TracerProvider.ERROR_MSG, "Not found exception", context);
                tracer.setAttribute(TracerProvider.ERROR_TYPE, throwable.getClass().getName(), context);
                tracer.end(statusCode, null, context);
            } else {
                tracer.setAttribute(TracerProvider.ERROR_MSG, throwable.getMessage(), context);
                tracer.setAttribute(TracerProvider.ERROR_TYPE, throwable.getClass().getName(), context);
                tracer.end(statusCode, throwable, context);
            }
        } else {
            tracer.end(statusCode, null, context);
        }
    }

Line commented on: tracer.setAttribute(TracerProvider.ERROR_MSG, throwable.getMessage(), context);

Revised code:
private void end(int statusCode, Throwable throwable, Context context) {
        if (throwable != null) {
            if (throwable instanceof CosmosException) {
                CosmosException cosmosException = (CosmosException) throwable;
                if (statusCode == HttpConstants.StatusCodes.NOTFOUND && cosmosException.getSubStatusCode() == 0) {
                    tracer.end(statusCode, null, context);
                    return;
                }
            }
        }
        tracer.end(statusCode, throwable, context);
    }
Code review comment: A switch will be more efficient since if it's TUPLE_VARIABLE_REF, it have to check 4 if-checks

Code under review:
private void checkDuplicateVarRefs(List<BLangExpression> varRefs, Set<BSymbol> symbols) {
        for (BLangExpression varRef : varRefs) {
            NodeKind kind = varRef.getKind();
            if (kind == NodeKind.SIMPLE_VARIABLE_REF) {
                BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) varRef;
                if (simpleVarRef.symbol != null && !symbols.add(simpleVarRef.symbol)) {
                    this.dlog.error(varRef.pos, DiagnosticErrorCode.DUPLICATE_VARIABLE_IN_BINDING_PATTERN,
                            simpleVarRef.symbol);
                }
            } else if (kind == NodeKind.RECORD_VARIABLE_REF) {
                checkDuplicateVarRefs(getVarRefs((BLangRecordVarRef) varRef), symbols);
            } else if (kind == NodeKind.ERROR_VARIABLE_REF) {
                checkDuplicateVarRefs(getVarRefs((BLangErrorVarRef) varRef), symbols);
            } else if (kind == NodeKind.TUPLE_VARIABLE_REF) {
                checkDuplicateVarRefs(getVarRefs((BLangTupleVarRef) varRef), symbols);
            }
        }
    }

Line commented on: if (kind == NodeKind.SIMPLE_VARIABLE_REF) {

Revised code:
private void checkDuplicateVarRefs(List<BLangExpression> varRefs, Set<BSymbol> symbols) {
        for (BLangExpression varRef : varRefs) {
            NodeKind kind = varRef.getKind();
            switch (kind) {
                case SIMPLE_VARIABLE_REF:
                    BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) varRef;
                    if (simpleVarRef.symbol != null && !symbols.add(simpleVarRef.symbol)) {
                        this.dlog.error(varRef.pos, DiagnosticErrorCode.DUPLICATE_VARIABLE_IN_BINDING_PATTERN,
                                simpleVarRef.symbol);
                    }
                    break;
                case RECORD_VARIABLE_REF:
                    checkDuplicateVarRefs(getVarRefs((BLangRecordVarRef) varRef), symbols);
                    break;
                case ERROR_VARIABLE_REF:
                    checkDuplicateVarRefs(getVarRefs((BLangErrorVarRef) varRef), symbols);
                    break;
                case TUPLE_VARIABLE_REF:
                    checkDuplicateVarRefs(getVarRefs((BLangTupleVarRef) varRef), symbols);
                    break;
                default:
            }
        }
    }