smiklosovic commented on code in PR #2983:
URL: https://github.com/apache/cassandra/pull/2983#discussion_r1428951281
##########
test/unit/org/apache/cassandra/service/StartupChecksTest.java:
##########
@@ -204,6 +216,104 @@ List<TableGCPeriod> getTablesGcPeriods(String
userKeyspace)
verifyFailure(startupChecks, "Invalid tables: abc.def");
}
+ private <R> void withPathOverriddingFileSystem(Map<String, String>
pathOverrides, Callable<? extends R> callable) throws Exception
+ {
+ Map<String, FileStore> fileStores =
Set.copyOf(pathOverrides.values()).stream().collect(Collectors.toMap(s -> s, s
-> {
+ FileStore fs = mock(FileStore.class);
+ when(fs.type()).thenReturn(s);
+ return fs;
+ }));
+ FileSystem savedFileSystem = File.unsafeGetFilesystem();
+ try
+ {
+ ForwardingFileSystemProvider fsp = new
ForwardingFileSystemProvider(savedFileSystem.provider())
+ {
+ @Override
+ public FileStore getFileStore(Path path) throws IOException
+ {
+ String override = pathOverrides.get(path.toString());
+ if (override != null)
+ return fileStores.get(override);
+
+ return super.getFileStore(path);
+ }
+ };
+
+ ForwardingFileSystem fs = new
ForwardingFileSystem(File.unsafeGetFilesystem())
+ {
+ private final FileSystem thisFileSystem = this;
+
+ @Override
+ public FileSystemProvider provider()
+ {
+ return fsp;
+ }
+
+ @Override
+ protected Path wrap(Path p)
+ {
+ return new ForwardingPath(p)
+ {
+ @Override
+ public FileSystem getFileSystem()
+ {
+ return thisFileSystem;
+ }
+ };
+ }
+ };
+ File.unsafeSetFilesystem(fs);
+ callable.call();
+ }
+ finally
+ {
+ File.unsafeSetFilesystem(savedFileSystem);
+ }
+ }
+
+ public void testKernelBugCheck(String fsType, DiskAccessMode
diskAccessMode, Semver kernelVersion, boolean expectToFail) throws Exception
+ {
+ String commitLogLocation =
Files.createTempDirectory("testKernelBugCheck").toString();
+
+ String savedCommitLogLocation =
DatabaseDescriptor.getCommitLogLocation();
+ DiskAccessMode savedCommitLogWriteDiskAccessMode =
DatabaseDescriptor.getCommitLogWriteDiskAccessMode();
+ Semver savedKernelVersion = FBUtilities.getKernelVersion();
+ try
+ {
+ DatabaseDescriptor.setCommitLogLocation(commitLogLocation);
+ DatabaseDescriptor.setCommitLogWriteDiskAccessMode(diskAccessMode);
+ DatabaseDescriptor.initializeCommitLogDiskAccessMode();
+
assertThat(DatabaseDescriptor.getCommitLogWriteDiskAccessMode()).isEqualTo(diskAccessMode);
+ FBUtilities.setKernelVersionSupplier(() -> kernelVersion);
+ withPathOverriddingFileSystem(Map.of(commitLogLocation, fsType),
() -> {
+ if (expectToFail)
+
assertThatExceptionOfType(StartupException.class).isThrownBy(() ->
StartupChecks.checkKernelBug1057843.execute(options));
+ else
+ StartupChecks.checkKernelBug1057843.execute(options);
+ return null;
+ });
+ }
+ finally
+ {
+ DatabaseDescriptor.setCommitLogLocation(savedCommitLogLocation);
+
DatabaseDescriptor.setCommitLogWriteDiskAccessMode(savedCommitLogWriteDiskAccessMode);
+ DatabaseDescriptor.initializeCommitLogDiskAccessMode();
+ FBUtilities.setKernelVersionSupplier(() -> savedKernelVersion);
+ }
+ }
+
+ @Test
+ public void testKernelBugCheck() throws Exception
Review Comment:
would be nice to add number of kernel bug this check checks into methods
name.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]