-
Notifications
You must be signed in to change notification settings - Fork 40
Backport to branch(3.14) : Add Cassandra permission test #2836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| name: Test Permissions | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| TERM: dumb | ||
| JAVA_VERSION: '8' | ||
| JAVA_VENDOR: 'temurin' | ||
|
|
||
| jobs: | ||
| integration-test-permission-cassandra-3-0: | ||
| name: Cassandra 3.0 Permission Integration Test | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK ${{ env.JAVA_VERSION }} (${{ env.JAVA_VENDOR }}) | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: ${{ env.JAVA_VERSION }} | ||
| distribution: ${{ env.JAVA_VENDOR }} | ||
|
|
||
| - name: Setup Gradle | ||
| uses: gradle/actions/setup-gradle@v4 | ||
|
|
||
| - name: Start Cassandra with authentication enabled | ||
| run: | | ||
| docker run -d --name cassandra \ | ||
| -p 9042:9042 \ | ||
| -e CASSANDRA_PASSWORD_SEEDER=yes \ | ||
| -e CASSANDRA_PASSWORD=cassandra \ | ||
| -e CASSANDRA_AUTHENTICATOR=PasswordAuthenticator \ | ||
| -e CASSANDRA_AUTHORIZER=CassandraAuthorizer \ | ||
| bitnami/cassandra:3.0 | ||
|
|
||
| - name: Wait for Cassandra to be ready | ||
| run: sleep 30 | ||
|
|
||
| - name: Execute Gradle 'integrationTestCassandraPermission' task | ||
| run: ./gradlew integrationTestCassandraPermission | ||
|
|
||
| - name: Upload Gradle test reports | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: cassandra_3.0_permission_integration_test_reports | ||
| path: core/build/reports/tests/integrationTestCassandraPermission | ||
|
|
||
| integration-test-permission-cassandra-3-11: | ||
| name: Cassandra 3.11 Permission Integration Test | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK ${{ env.JAVA_VERSION }} (${{ env.JAVA_VENDOR }}) | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: ${{ env.JAVA_VERSION }} | ||
| distribution: ${{ env.JAVA_VENDOR }} | ||
|
|
||
| - name: Setup Gradle | ||
| uses: gradle/actions/setup-gradle@v4 | ||
|
|
||
| - name: Start Cassandra with authentication enabled | ||
| run: | | ||
| docker run -d --name cassandra \ | ||
| -p 9042:9042 \ | ||
| -e CASSANDRA_PASSWORD_SEEDER=yes \ | ||
| -e CASSANDRA_PASSWORD=cassandra \ | ||
| -e CASSANDRA_AUTHENTICATOR=PasswordAuthenticator \ | ||
| -e CASSANDRA_AUTHORIZER=CassandraAuthorizer \ | ||
| bitnami/cassandra:3.11 | ||
|
|
||
| - name: Wait for Cassandra to be ready | ||
| run: sleep 30 | ||
|
|
||
| - name: Execute Gradle 'integrationTestCassandraPermission' task | ||
| run: ./gradlew integrationTestCassandraPermission | ||
|
|
||
| - name: Upload Gradle test reports | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: cassandra_3.11_permission_integration_test_reports | ||
| path: core/build/reports/tests/integrationTestCassandraPermission |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| package com.scalar.db.storage.cassandra; | ||
|
|
||
| import static com.scalar.db.storage.cassandra.CassandraPermissionTestUtils.MAX_RETRY_COUNT; | ||
| import static com.scalar.db.storage.cassandra.CassandraPermissionTestUtils.SLEEP_BETWEEN_RETRIES_SECONDS; | ||
|
|
||
| import com.google.common.util.concurrent.Uninterruptibles; | ||
| import com.scalar.db.api.DistributedStorageAdminPermissionIntegrationTestBase; | ||
| import com.scalar.db.util.AdminTestUtils; | ||
| import com.scalar.db.util.PermissionTestUtils; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.Properties; | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class CassandraAdminPermissionIntegrationTest | ||
| extends DistributedStorageAdminPermissionIntegrationTestBase { | ||
| @Override | ||
| protected Properties getProperties(String testName) { | ||
| return CassandraEnv.getProperties(testName); | ||
| } | ||
|
|
||
| @Override | ||
| protected Properties getPropertiesForNormalUser(String testName) { | ||
| return CassandraEnv.getPropertiesForNormalUser(testName); | ||
| } | ||
|
|
||
| @Override | ||
| protected AdminTestUtils getAdminTestUtils(String testName) { | ||
| return new CassandraAdminTestUtils(getProperties(testName)); | ||
| } | ||
|
|
||
| @Override | ||
| protected PermissionTestUtils getPermissionTestUtils(String testName) { | ||
| return new CassandraPermissionTestUtils(getProperties(testName)); | ||
| } | ||
|
|
||
| @Override | ||
| protected Map<String, String> getCreationOptions() { | ||
| return Collections.singletonMap(CassandraAdmin.REPLICATION_FACTOR, "1"); | ||
| } | ||
|
|
||
| @Override | ||
| protected void waitForNamespaceCreation() { | ||
| try { | ||
| AdminTestUtils utils = getAdminTestUtils(TEST_NAME); | ||
| int retryCount = 0; | ||
| while (retryCount < MAX_RETRY_COUNT) { | ||
| if (utils.namespaceExists(NAMESPACE)) { | ||
| utils.close(); | ||
| return; | ||
| } | ||
| Uninterruptibles.sleepUninterruptibly( | ||
| SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.SECONDS); | ||
| retryCount++; | ||
| } | ||
| utils.close(); | ||
| throw new RuntimeException("Namespace was not created after " + MAX_RETRY_COUNT + " retries"); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to wait for namespace creation", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void waitForTableCreation() { | ||
| try { | ||
| AdminTestUtils utils = getAdminTestUtils(TEST_NAME); | ||
| int retryCount = 0; | ||
| while (retryCount < MAX_RETRY_COUNT) { | ||
| if (utils.tableExists(NAMESPACE, TABLE)) { | ||
| utils.close(); | ||
| return; | ||
| } | ||
| Uninterruptibles.sleepUninterruptibly( | ||
| SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.SECONDS); | ||
| retryCount++; | ||
| } | ||
| utils.close(); | ||
| throw new RuntimeException("Table was not created after " + MAX_RETRY_COUNT + " retries"); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to wait for table creation", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void waitForNamespaceDeletion() { | ||
| try { | ||
| AdminTestUtils utils = getAdminTestUtils(TEST_NAME); | ||
| int retryCount = 0; | ||
| while (retryCount < MAX_RETRY_COUNT) { | ||
| if (!utils.namespaceExists(NAMESPACE)) { | ||
| utils.close(); | ||
| return; | ||
| } | ||
| Uninterruptibles.sleepUninterruptibly( | ||
| SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.SECONDS); | ||
| retryCount++; | ||
| } | ||
| utils.close(); | ||
| throw new RuntimeException("Namespace was not deleted after " + MAX_RETRY_COUNT + " retries"); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to wait for namespace deletion", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void waitForTableDeletion() { | ||
| try { | ||
| AdminTestUtils utils = getAdminTestUtils(TEST_NAME); | ||
| int retryCount = 0; | ||
| while (retryCount < MAX_RETRY_COUNT) { | ||
| if (!utils.tableExists(NAMESPACE, TABLE)) { | ||
| utils.close(); | ||
| return; | ||
| } | ||
| Uninterruptibles.sleepUninterruptibly( | ||
| SLEEP_BETWEEN_RETRIES_SECONDS, java.util.concurrent.TimeUnit.SECONDS); | ||
| retryCount++; | ||
| } | ||
| utils.close(); | ||
| throw new RuntimeException("Table was not deleted after " + MAX_RETRY_COUNT + " retries"); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to wait for table deletion", e); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @Override | ||
| @Disabled("Import-related functionality is not supported in Cassandra") | ||
| public void getImportTableMetadata_WithSufficientPermission_ShouldSucceed() {} | ||
|
|
||
| @Test | ||
| @Override | ||
| @Disabled("Import-related functionality is not supported in Cassandra") | ||
| public void addRawColumnToTable_WithSufficientPermission_ShouldSucceed() {} | ||
|
|
||
| @Test | ||
| @Override | ||
| @Disabled("Import-related functionality is not supported in Cassandra") | ||
| public void importTable_WithSufficientPermission_ShouldSucceed() {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,61 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package com.scalar.db.storage.cassandra; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static com.scalar.db.storage.cassandra.CassandraPermissionTestUtils.MAX_RETRY_COUNT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static com.scalar.db.storage.cassandra.CassandraPermissionTestUtils.SLEEP_BETWEEN_RETRIES_SECONDS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.google.common.util.concurrent.Uninterruptibles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.scalar.db.api.DistributedStoragePermissionIntegrationTestBase; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.scalar.db.util.AdminTestUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.scalar.db.util.PermissionTestUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Collections; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Properties; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.concurrent.TimeUnit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class CassandraPermissionIntegrationTest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extends DistributedStoragePermissionIntegrationTestBase { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected Properties getProperties(String testName) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CassandraEnv.getProperties(testName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected Properties getPropertiesForNormalUser(String testName) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return CassandraEnv.getPropertiesForNormalUser(testName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected PermissionTestUtils getPermissionTestUtils(String testName) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new CassandraPermissionTestUtils(getProperties(testName)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected AdminTestUtils getAdminTestUtils(String testName) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new CassandraAdminTestUtils(getProperties(testName)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected Map<String, String> getCreationOptions() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Collections.singletonMap(CassandraAdmin.REPLICATION_FACTOR, "1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected void waitForTableCreation() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AdminTestUtils utils = getAdminTestUtils(TEST_NAME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int retryCount = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while (retryCount < MAX_RETRY_COUNT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (utils.tableExists(NAMESPACE, TABLE)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| utils.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Uninterruptibles.sleepUninterruptibly(SLEEP_BETWEEN_RETRIES_SECONDS, TimeUnit.SECONDS); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| retryCount++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| utils.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new RuntimeException("Table was not created after " + MAX_RETRY_COUNT + " retries"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new RuntimeException("Failed to wait for table creation", e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method has a potential resource leak. If an exception is thrown from within the A
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method has a potential resource leak. If an exception is thrown from within the
whileloop (e.g., fromutils.namespaceExists()), thecatchblock will be executed withoututils.close()being called. This could leave resources open. Use afinallyblock to ensureutils.close()is always called.Additionally, the four
waitFor...methods in this class are nearly identical. Consider refactoring them into a single private helper method to reduce code duplication and improve maintainability.