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);
}
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();
}
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();
}
}
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);
}
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
}
}
Aggregations