Search in sources :

Example 1 with ParameterizedClass

use of org.apache.cassandra.config.ParameterizedClass in project cassandra by apache.

the class AuditLoggerAuthTest method setup.

@BeforeClass
public static void setup() throws Exception {
    OverrideConfigurationLoader.override((config) -> {
        config.authenticator = "PasswordAuthenticator";
        config.role_manager = "CassandraRoleManager";
        config.authorizer = "CassandraAuthorizer";
        config.audit_logging_options.enabled = true;
        config.audit_logging_options.logger = new ParameterizedClass("InMemoryAuditLogger", null);
    });
    CQLTester.prepareServer();
    System.setProperty("cassandra.superuser_setup_delay_ms", "0");
    embedded = new EmbeddedCassandraService();
    embedded.start();
    executeWithCredentials(Arrays.asList(getCreateRoleCql(TEST_USER, true, false, false), getCreateRoleCql("testuser_nologin", false, false, false), "CREATE KEYSPACE testks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}", "CREATE TABLE testks.table1 (key text PRIMARY KEY, col1 int, col2 int)"), "cassandra", "cassandra", null);
}
Also used : ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) EmbeddedCassandraService(org.apache.cassandra.service.EmbeddedCassandraService) BeforeClass(org.junit.BeforeClass)

Example 2 with ParameterizedClass

use of org.apache.cassandra.config.ParameterizedClass in project cassandra by apache.

the class AuditLoggerTest method setUp.

@BeforeClass
public static void setUp() {
    AuditLogOptions options = new AuditLogOptions();
    options.enabled = true;
    options.logger = new ParameterizedClass("InMemoryAuditLogger", null);
    DatabaseDescriptor.setAuditLoggingOptions(options);
    requireNetwork();
}
Also used : ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) BeforeClass(org.junit.BeforeClass)

Example 3 with ParameterizedClass

use of org.apache.cassandra.config.ParameterizedClass in project cassandra by apache.

the class CommitLogSegmentBackpressureTest method testCompressedCommitLogBackpressure.

@Test
@BMRules(rules = { @BMRule(name = "Acquire Semaphore before sync", targetClass = "AbstractCommitLogService$SyncRunnable", targetMethod = "run", targetLocation = "AT INVOKE org.apache.cassandra.db.commitlog.CommitLog.sync(boolean)", action = "org.apache.cassandra.db.commitlog.CommitLogSegmentBackpressureTest.allowSync.acquire()"), @BMRule(name = "Release Semaphore after sync", targetClass = "AbstractCommitLogService$SyncRunnable", targetMethod = "run", targetLocation = "AFTER INVOKE org.apache.cassandra.db.commitlog.CommitLog.sync(boolean)", action = "org.apache.cassandra.db.commitlog.CommitLogSegmentBackpressureTest.allowSync.release()") })
public void testCompressedCommitLogBackpressure() throws Throwable {
    // Perform all initialization before making CommitLog.Sync blocking
    // Doing the initialization within the method guarantee that Byteman has performed its injections when we start
    new Random().nextBytes(entropy);
    DatabaseDescriptor.daemonInitialization();
    DatabaseDescriptor.setCommitLogCompression(new ParameterizedClass("LZ4Compressor", ImmutableMap.of()));
    DatabaseDescriptor.setCommitLogSegmentSize(1);
    DatabaseDescriptor.setCommitLogSync(CommitLogSync.periodic);
    DatabaseDescriptor.setCommitLogSyncPeriod(10 * 1000);
    DatabaseDescriptor.setCommitLogMaxCompressionBuffersPerPool(3);
    SchemaLoader.prepareServer();
    SchemaLoader.createKeyspace(KEYSPACE1, KeyspaceParams.simple(1), SchemaLoader.standardCFMD(KEYSPACE1, STANDARD1, 0, AsciiType.instance, BytesType.instance), SchemaLoader.standardCFMD(KEYSPACE1, STANDARD2, 0, AsciiType.instance, BytesType.instance));
    CompactionManager.instance.disableAutoCompaction();
    ColumnFamilyStore cfs1 = Keyspace.open(KEYSPACE1).getColumnFamilyStore(STANDARD1);
    final Mutation m = new RowUpdateBuilder(cfs1.metadata(), 0, "k").clustering("bytes").add("val", ByteBuffer.wrap(entropy)).build();
    Thread dummyThread = new Thread(() -> {
        for (int i = 0; i < 20; i++) CommitLog.instance.add(m);
    });
    try {
        // Makes sure any call to CommitLog.sync is blocking
        allowSync.acquire();
        dummyThread.start();
        AbstractCommitLogSegmentManager clsm = CommitLog.instance.segmentManager;
        Util.spinAssertEquals(3, () -> clsm.getActiveSegments().size(), 5);
        Thread.sleep(1000);
        // Should only be able to create 3 segments not 7 because it blocks waiting for truncation that never comes
        Assert.assertEquals(3, clsm.getActiveSegments().size());
        // Discard the currently active segments so allocation can continue.
        // Take snapshot of the list, otherwise this will also discard newly allocated segments.
        new ArrayList<>(clsm.getActiveSegments()).forEach(clsm::archiveAndDiscard);
        // The allocated count should reach the limit again.
        Util.spinAssertEquals(3, () -> clsm.getActiveSegments().size(), 5);
    } finally {
        // Allow the CommitLog.sync to perform normally.
        allowSync.release();
    }
    try {
        // Wait for the dummy thread to die
        dummyThread.join();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : Random(java.util.Random) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Mutation(org.apache.cassandra.db.Mutation) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 4 with ParameterizedClass

use of org.apache.cassandra.config.ParameterizedClass in project cassandra by apache.

the class CommitLogTest method testRecoveryWithBadCompressor.

@Test
public void testRecoveryWithBadCompressor() throws Exception {
    CommitLogDescriptor desc = new CommitLogDescriptor(4, new ParameterizedClass("UnknownCompressor", null), EncryptionContextGenerator.createDisabledContext());
    runExpecting(() -> {
        testRecovery(desc, new byte[0]);
        return null;
    }, CommitLogReplayException.class);
}
Also used : ParameterizedClass(org.apache.cassandra.config.ParameterizedClass)

Example 5 with ParameterizedClass

use of org.apache.cassandra.config.ParameterizedClass in project cassandra by apache.

the class CommitLogDescriptorTest method testDescriptorInvalidParametersSize.

// migrated from CommitLogTest
@Test
public void testDescriptorInvalidParametersSize() throws IOException {
    Map<String, String> params = new HashMap<>();
    for (int i = 0; i < 65535; ++i) params.put("key" + i, Integer.toString(i, 16));
    try {
        CommitLogDescriptor desc = new CommitLogDescriptor(CommitLogDescriptor.current_version, 21, new ParameterizedClass("LZ4Compressor", params), neverEnabledEncryption);
        ByteBuffer buf = ByteBuffer.allocate(1024000);
        CommitLogDescriptor.writeHeader(buf, desc);
        Assert.fail("Parameter object too long should fail on writing descriptor.");
    } catch (ConfigurationException e) {
    // correct path
    }
}
Also used : HashMap(java.util.HashMap) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

ParameterizedClass (org.apache.cassandra.config.ParameterizedClass)17 Test (org.junit.Test)8 HashMap (java.util.HashMap)5 BeforeClass (org.junit.BeforeClass)4 Random (java.util.Random)3 EncryptionOptions (org.apache.cassandra.config.EncryptionOptions)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 Mutation (org.apache.cassandra.db.Mutation)3 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)3 ServerEncryptionOptions (org.apache.cassandra.config.EncryptionOptions.ServerEncryptionOptions)2 TransparentDataEncryptionOptions (org.apache.cassandra.config.TransparentDataEncryptionOptions)2 EncryptionContext (org.apache.cassandra.security.EncryptionContext)2 EmbeddedCassandraService (org.apache.cassandra.service.EmbeddedCassandraService)2 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 OpenSslContext (io.netty.handler.ssl.OpenSslContext)1 SslContext (io.netty.handler.ssl.SslContext)1 ByteBuffer (java.nio.ByteBuffer)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 File (org.apache.cassandra.io.util.File)1