use of org.apache.kafka.common.metadata.AccessControlEntryRecord in project kafka by apache.
the class StandardAclWithIdTest method testToRecordRoundTrips.
@Test
public void testToRecordRoundTrips() {
for (StandardAclWithId acl : TEST_ACLS) {
AccessControlEntryRecord record = acl.toRecord();
StandardAclWithId acl2 = StandardAclWithId.fromRecord(record);
assertEquals(acl2, acl);
}
}
use of org.apache.kafka.common.metadata.AccessControlEntryRecord in project kafka by apache.
the class AclControlManagerTest method testLoadSnapshot.
@Test
public void testLoadSnapshot() {
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
snapshotRegistry.getOrCreateSnapshot(0);
AclControlManager manager = new AclControlManager(snapshotRegistry, Optional.empty());
// Load TEST_ACLS into the AclControlManager.
Set<ApiMessageAndVersion> loadedAcls = new HashSet<>();
for (StandardAclWithId acl : TEST_ACLS) {
AccessControlEntryRecord record = acl.toRecord();
assertTrue(loadedAcls.add(new ApiMessageAndVersion(record, (short) 0)));
manager.replay(acl.toRecord(), Optional.empty());
}
// Verify that the ACLs stored in the AclControlManager match the ones we expect.
Set<ApiMessageAndVersion> foundAcls = new HashSet<>();
for (Iterator<List<ApiMessageAndVersion>> iterator = manager.iterator(Long.MAX_VALUE); iterator.hasNext(); ) {
for (ApiMessageAndVersion apiMessageAndVersion : iterator.next()) {
assertTrue(foundAcls.add(apiMessageAndVersion));
}
}
assertEquals(loadedAcls, foundAcls);
// Once we complete the snapshot load, the ACLs should be reflected in the authorizer.
MockClusterMetadataAuthorizer authorizer = new MockClusterMetadataAuthorizer();
authorizer.loadSnapshot(manager.idToAcl());
assertEquals(new HashSet<>(StandardAclTest.TEST_ACLS), new HashSet<>(authorizer.acls.values()));
// Test reverting to an empty state and then completing the snapshot load without
// setting an authorizer. This simulates the case where the user didn't configure
// a cluster metadata authorizer.
snapshotRegistry.revertToSnapshot(0);
authorizer.loadSnapshot(manager.idToAcl());
assertFalse(manager.iterator(Long.MAX_VALUE).hasNext());
}
Aggregations