You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "yifan-c (via GitHub)" <gi...@apache.org> on 2024/05/13 18:52:49 UTC
[PR] CASSANDRASC-131: Reset system properties to avoid integration test pollution [cassandra-sidecar]
yifan-c opened a new pull request, #122:
URL: https://github.com/apache/cassandra-sidecar/pull/122
Patch by Yifan Cai; Reviewed by Francisco Guerrero for CASSANDRASC-131
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRASC-131: Reset system properties to avoid integration test pollution [cassandra-sidecar]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c merged PR #122:
URL: https://github.com/apache/cassandra-sidecar/pull/122
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRASC-131: Reset system properties to avoid integration test pollution [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #122:
URL: https://github.com/apache/cassandra-sidecar/pull/122#discussion_r1602292809
##########
src/main/java/org/apache/cassandra/sidecar/restore/RestoreJobManager.java:
##########
@@ -206,10 +221,9 @@ private Future<Void> deleteDataAsync(Path root)
{
pathStream
.sorted(Comparator.reverseOrder())
- .map(Path::toFile)
- .forEach(File::delete);
+ .forEach(path -> ThrowableUtils.propogate(() -> Files.delete(path)));
}
- catch (IOException ioe) // thrown from Files.walk.
+ catch (Exception ioe)
Review Comment:
```suggestion
catch (Exception exception)
```
##########
src/main/java/org/apache/cassandra/sidecar/exceptions/ThrowableUtils.java:
##########
@@ -18,23 +18,49 @@
package org.apache.cassandra.sidecar.exceptions;
+import java.util.concurrent.Callable;
import java.util.function.Predicate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.cassandra.sidecar.common.server.ThrowingRunnable;
/**
* Collection of utility methods for understanding {@link Throwable} thrown better
*/
public class ThrowableUtils
{
- private static final Logger LOGGER = LoggerFactory.getLogger(ThrowableUtils.class);
-
private ThrowableUtils()
{
throw new UnsupportedOperationException();
}
+ /**
+ * Run the {@code actionMayThrow} and wrap any {@link Exception} thrown in {@link RuntimeException}
+ * @param actionMayThrow action that may throw exceptions
+ * @param <R> return value type of the action
+ */
+ public static <R> R propogate(Callable<R> actionMayThrow)
+ {
+ try
+ {
+ return actionMayThrow.call();
+ }
+ catch (Exception cause)
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
+ /**
+ * Similar to {@link #propogate(Callable)}, but takes runnable-ish
+ */
+ public static void propogate(ThrowingRunnable actionMayThrow)
Review Comment:
```suggestion
public static void propagate(ThrowingRunnable actionMayThrow)
```
##########
src/main/java/org/apache/cassandra/sidecar/exceptions/ThrowableUtils.java:
##########
@@ -18,23 +18,49 @@
package org.apache.cassandra.sidecar.exceptions;
+import java.util.concurrent.Callable;
import java.util.function.Predicate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.cassandra.sidecar.common.server.ThrowingRunnable;
/**
* Collection of utility methods for understanding {@link Throwable} thrown better
*/
public class ThrowableUtils
{
- private static final Logger LOGGER = LoggerFactory.getLogger(ThrowableUtils.class);
-
private ThrowableUtils()
{
throw new UnsupportedOperationException();
}
+ /**
+ * Run the {@code actionMayThrow} and wrap any {@link Exception} thrown in {@link RuntimeException}
+ * @param actionMayThrow action that may throw exceptions
+ * @param <R> return value type of the action
+ */
+ public static <R> R propogate(Callable<R> actionMayThrow)
Review Comment:
```suggestion
public static <R> R propagate(Callable<R> actionMayThrow)
```
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRASC-131: Reset system properties to avoid integration test pollution [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #122:
URL: https://github.com/apache/cassandra-sidecar/pull/122#discussion_r1598946750
##########
src/test/integration/org/apache/cassandra/testing/AbstractCassandraTestContext.java:
##########
@@ -82,11 +85,43 @@ public void close()
throw t;
}
}
+ finally
+ {
+ LOGGER.info("Restoring system properties");
+ Map<String, String> currentProps = systemStringProperties();
+ currentProps.forEach((k, v) -> {
+ if (initialProperties.containsKey(k))
+ {
+ String initialValue = initialProperties.get(k);
+ if (!v.equals(initialValue))
+ {
+ System.setProperty(k, initialValue); // restore to the initial value
+ }
+ }
+ else
+ {
+ System.clearProperty(k); // remove the added property during test
+ }
+ });
Review Comment:
can you move this block into a method?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org