|
36 | 36 | import java.util.concurrent.ConcurrentHashMap; |
37 | 37 | import java.util.concurrent.CountDownLatch; |
38 | 38 | import java.util.concurrent.TimeUnit; |
| 39 | +import java.util.function.BooleanSupplier; |
39 | 40 | import java.util.function.Consumer; |
40 | 41 | import java.util.function.Function; |
41 | 42 | import java.util.stream.Collectors; |
|
88 | 89 | import org.apache.cassandra.sidecar.common.server.utils.SidecarVersionProvider; |
89 | 90 | import org.apache.cassandra.sidecar.common.server.utils.ThrowableUtils; |
90 | 91 | import org.apache.cassandra.sidecar.config.JmxConfiguration; |
91 | | -import org.apache.cassandra.sidecar.config.KeyStoreConfiguration; |
92 | 92 | import org.apache.cassandra.sidecar.config.S3ClientConfiguration; |
93 | 93 | import org.apache.cassandra.sidecar.config.S3ProxyConfiguration; |
94 | 94 | import org.apache.cassandra.sidecar.config.ServiceConfiguration; |
95 | 95 | import org.apache.cassandra.sidecar.config.SidecarConfiguration; |
96 | 96 | import org.apache.cassandra.sidecar.config.SslConfiguration; |
97 | | -import org.apache.cassandra.sidecar.config.yaml.KeyStoreConfigurationImpl; |
98 | 97 | import org.apache.cassandra.sidecar.config.yaml.S3ClientConfigurationImpl; |
99 | 98 | import org.apache.cassandra.sidecar.config.yaml.SchemaKeyspaceConfigurationImpl; |
100 | | -import org.apache.cassandra.sidecar.config.yaml.ServiceConfigurationImpl; |
101 | 99 | import org.apache.cassandra.sidecar.config.yaml.SidecarConfigurationImpl; |
102 | | -import org.apache.cassandra.sidecar.config.yaml.SslConfigurationImpl; |
| 100 | +import org.apache.cassandra.sidecar.config.yaml.TestServiceConfiguration; |
103 | 101 | import org.apache.cassandra.sidecar.coordination.ClusterLease; |
104 | 102 | import org.apache.cassandra.sidecar.lifecycle.InJvmDTestLifecycleProvider; |
105 | 103 | import org.apache.cassandra.sidecar.lifecycle.LifecycleProvider; |
|
116 | 114 | import org.apache.cassandra.testing.TestVersionSupplier; |
117 | 115 |
|
118 | 116 | import static org.apache.cassandra.sidecar.config.yaml.S3ClientConfigurationImpl.DEFAULT_API_CALL_TIMEOUT; |
119 | | -import static org.apache.cassandra.sidecar.testing.MtlsTestHelper.CASSANDRA_INTEGRATION_TEST_ENABLE_MTLS; |
120 | 117 | import static org.apache.cassandra.testing.DriverTestUtils.buildContactPoints; |
121 | 118 | import static org.apache.cassandra.testing.utils.IInstanceUtils.tryGetIntConfig; |
122 | 119 | import static org.assertj.core.api.Assertions.assertThat; |
@@ -440,6 +437,30 @@ protected void waitForSchemaReady(ServerWrapper serverWrapper, long timeout, Tim |
440 | 437 | .isTrue(); |
441 | 438 | } |
442 | 439 |
|
| 440 | + /** |
| 441 | + * Polls a condition until it returns true or timeout is reached. |
| 442 | + * Uses System.nanoTime() for accurate timing and Uninterruptibles for consistent sleep behavior. |
| 443 | + * |
| 444 | + * @param condition the condition to check |
| 445 | + * @param timeoutSeconds maximum time to wait in seconds |
| 446 | + * @param pollIntervalMillis interval between checks in milliseconds |
| 447 | + * @throws AssertionError if timeout is reached before condition is met |
| 448 | + */ |
| 449 | + protected void waitUntil(BooleanSupplier condition, long timeoutSeconds, long pollIntervalMillis) |
| 450 | + { |
| 451 | + long startTime = System.nanoTime(); |
| 452 | + long timeoutNanos = TimeUnit.SECONDS.toNanos(timeoutSeconds); |
| 453 | + |
| 454 | + while (!condition.getAsBoolean()) |
| 455 | + { |
| 456 | + if (System.nanoTime() - startTime > timeoutNanos) |
| 457 | + { |
| 458 | + throw new AssertionError("Condition not met within " + timeoutSeconds + " seconds"); |
| 459 | + } |
| 460 | + Uninterruptibles.sleepUninterruptibly(pollIntervalMillis, TimeUnit.MILLISECONDS); |
| 461 | + } |
| 462 | + } |
| 463 | + |
443 | 464 | /** |
444 | 465 | * Stops the Sidecar service |
445 | 466 | * |
@@ -775,48 +796,23 @@ public LifecycleProvider lifecycleProvider() |
775 | 796 | } |
776 | 797 |
|
777 | 798 | public static SidecarConfigurationImpl.Builder defaultConfigurationBuilder( |
778 | | - MtlsTestHelper mtlsTestHelper, Function<SidecarConfigurationImpl.Builder, SidecarConfigurationImpl.Builder> configurationOverrides) |
| 799 | + MtlsTestHelper mtlsTestHelper, |
| 800 | + Function<SidecarConfigurationImpl.Builder, SidecarConfigurationImpl.Builder> configurationOverrides) |
779 | 801 | { |
780 | | - ServiceConfiguration conf = ServiceConfigurationImpl.builder() |
781 | | - .host("0.0.0.0") // binds to all interfaces, potential security issue if left running for long |
782 | | - .port(0) // let the test find an available port |
| 802 | + ServiceConfiguration conf = TestServiceConfiguration.builder() |
783 | 803 | .schemaKeyspaceConfiguration(SchemaKeyspaceConfigurationImpl.builder() |
784 | 804 | .isEnabled(true) |
785 | 805 | .build()) |
786 | 806 | .build(); |
787 | 807 |
|
788 | | - |
789 | | - SslConfiguration sslConfiguration = null; |
790 | | - if (mtlsTestHelper.isEnabled()) |
791 | | - { |
792 | | - LOGGER.info("Enabling test mTLS certificate/keystore."); |
793 | | - |
794 | | - KeyStoreConfiguration truststoreConfiguration = |
795 | | - new KeyStoreConfigurationImpl(mtlsTestHelper.trustStorePath(), |
796 | | - mtlsTestHelper.trustStorePassword(), |
797 | | - mtlsTestHelper.trustStoreType(), |
798 | | - SecondBoundConfiguration.parse("60s")); |
799 | | - |
800 | | - KeyStoreConfiguration keyStoreConfiguration = |
801 | | - new KeyStoreConfigurationImpl(mtlsTestHelper.serverKeyStorePath(), |
802 | | - mtlsTestHelper.serverKeyStorePassword(), |
803 | | - mtlsTestHelper.serverKeyStoreType(), |
804 | | - SecondBoundConfiguration.parse("60s")); |
805 | | - |
806 | | - sslConfiguration = SslConfigurationImpl.builder() |
807 | | - .enabled(true) |
808 | | - .keystore(keyStoreConfiguration) |
809 | | - .truststore(truststoreConfiguration) |
810 | | - .build(); |
811 | | - } |
812 | | - else |
813 | | - { |
814 | | - LOGGER.info("Not enabling mTLS for testing purposes. Set '{}' to 'true' if you would " + |
815 | | - "like mTLS enabled.", CASSANDRA_INTEGRATION_TEST_ENABLE_MTLS); |
816 | | - } |
817 | | - S3ClientConfiguration s3ClientConfig = new S3ClientConfigurationImpl("s3-client", 4, SecondBoundConfiguration.parse("60s"), |
818 | | - 5242880, DEFAULT_API_CALL_TIMEOUT, |
819 | | - buildTestS3ProxyConfig()); |
| 808 | + SslConfiguration sslConfiguration = mtlsTestHelper.createServerSslConfiguration(); |
| 809 | + S3ClientConfiguration s3ClientConfig = |
| 810 | + new S3ClientConfigurationImpl("s3-client", |
| 811 | + 4, |
| 812 | + SecondBoundConfiguration.parse("60s"), |
| 813 | + 5242880, |
| 814 | + DEFAULT_API_CALL_TIMEOUT, |
| 815 | + buildTestS3ProxyConfig()); |
820 | 816 |
|
821 | 817 | SidecarConfigurationImpl.Builder builder = SidecarConfigurationImpl.builder() |
822 | 818 | .serviceConfiguration(conf) |
|
0 commit comments