[
https://issues.apache.org/jira/browse/KAFKA-1101?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15853984#comment-15853984
]
Enrico Olivelli commented on KAFKA-1101:
----------------------------------------
Just for completeness, I had to add some hacks to make Maven Surefire plugin
work
{code}
public class NoExitSecurityManager extends SecurityManager {
private final SecurityManager wrapped;
public NoExitSecurityManager() {
wrapped = new SecurityManager();
Policy.setPolicy(new Policy() {
final Permissions pc = new Permissions();
{
pc.add(new AllPermission());
}
@Override
public boolean implies(ProtectionDomain domain, Permission
permission) {
return true;
}
@Override
public PermissionCollection getPermissions(ProtectionDomain domain)
{
return pc;
}
@Override
public PermissionCollection getPermissions(CodeSource codesource) {
return pc;
}
});
}
public NoExitSecurityManager(SecurityManager wrapped) {
this.wrapped = wrapped;
}
@Override
public void checkExit(int status) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
if (stackTrace != null) {
for (StackTraceElement el : stackTrace) {
if (el.getClassName() != null
&&
el.getClassName().startsWith("org.apache.maven.surefire.booter.ForkedBooter")
&& "exit".equals(el.getMethodName())) {
return;
}
}
}
throw new SecurityException("System.exit is disabled on unit tests");
}
@Override
public void checkPermission(Permission perm) {
if (wrapped == null) {
return;
}
wrapped.checkPermission(perm); //To change body of generated methods,
choose Tools | Templates.
}
}
{code}
> Need better java api for embedding kafkaserver in a java container app
> ----------------------------------------------------------------------
>
> Key: KAFKA-1101
> URL: https://issues.apache.org/jira/browse/KAFKA-1101
> Project: Kafka
> Issue Type: Bug
> Reporter: Jason Rosenberg
>
> We embed the KafkaServer inside a java service container framework, which
> makes it easy to deploy and monitor within our infrastructure. When
> upgrading to kafka 0.8 from 0.7.2, I ran into an issue with not being able to
> pass the needed constructor arg (SystemTime), since there doesn't appear to
> be an easy way to instantiate that from java. So, I ended up with this janky
> solution using SystemTime$.MODULE$.
> Could a default constructor be added which assumes a default SystemTime,
> rather than requiring that here?
> Note, I need to construct a KafkaServer directly, since I need to manage the
> lifecycle more directly than can be done with KafkaServerStartable.
> {code}
> // Need to do janky scala MODULE$ dereferencing, in order to get a
> default value in ctor
> server = new kafka.server.KafkaServer(kafkaConfig, SystemTime$.MODULE$);
> server.startup();
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)