I have the following test code:
herder = PowerMock.createPartialMock(DistributedHerder.class, new String[]{"backoff", "updateDeletedConnectorStatus"},
new DistributedConfig(HERDER_CONFIG), worker, WORKER_ID, statusBackingStore, configBackingStore, member, MEMBER_URL, time);
configUpdateListener = herder.new ConfigUpdateListener();
rebalanceListener = herder.new RebalanceListener();
plugins = PowerMock.createMock(Plugins.class);
EasyMock.expect(worker.getPlugins()).andReturn(plugins);
EasyMock.expect(herder.connectorType(CONN1)).andReturn(ConnectorType.SOURCE).anyTimes();
where connectorType() method is defined in AbstractHerder, base class of DistributedHerder. Since the herder is created off of DistributedHerder, easy mock doesn't find mock for AbstractHerder class, leading to NPE:
org.apache.kafka.connect.runtime.distributed.DistributedHerderTest > testInconsistentConfigs FAILED
java.lang.NullPointerException
at org.apache.kafka.connect.runtime.AbstractHerder.getConnector(AbstractHerder.java:342)
at org.apache.kafka.connect.runtime.distributed.DistributedHerder$$EnhancerByCGLIB$$af0dd240.CGLIB$getConnector$39(<generated>)
at org.apache.kafka.connect.runtime.distributed.DistributedHerder$$EnhancerByCGLIB$$af0dd240$$FastClassByCGLIB$$8c31132d.invoke(<generated>)
at org.easymock.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.easymock.internal.ClassProxyFactory$MockMethodInterceptor.intercept(ClassProxyFactory.java:92)
at org.apache.kafka.connect.runtime.distributed.DistributedHerder$$EnhancerByCGLIB$$af0dd240.getConnector(<generated>)
at org.apache.kafka.connect.runtime.AbstractHerder.connectorType(AbstractHerder.java:349)
at org.apache.kafka.connect.runtime.distributed.DistributedHerder$$EnhancerByCGLIB$$af0dd240.CGLIB$connectorType$23(<generated>)
at org.apache.kafka.connect.runtime.distributed.DistributedHerder$$EnhancerByCGLIB$$af0dd240$$FastClassByCGLIB$$8c31132d.invoke(<generated>)
at org.easymock.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.easymock.internal.ClassProxyFactory$MockMethodInterceptor.intercept(ClassProxyFactory.java:92)
at org.apache.kafka.connect.runtime.distributed.DistributedHerder$$EnhancerByCGLIB$$af0dd240.connectorType(<generated>)
at org.apache.kafka.connect.runtime.distributed.DistributedHerderTest.setUp(DistributedHerderTest.java:179)
Any hint is welcome.
I am a bit lost here but will still try to give some hints in terms of Socratic questions.
DistributedHerder
? It looks like a normal partial mocking Plugins
instead of plain EasyMock? herder.new ConfigUpdateListener()
? Which language is that? worker
? replay()
indeed. Can we have the full code? backoff
and updateDeletedConnectorStatus
. Is that normal? plugins()
method is returning null. This one isn't mocked so it probably just return null indeed no?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.