-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-8058: Fix ConnectClusterStateImpl.connectors() method (#6384)
Fixed the ConnectClusterStateImpl.connectors() method and throw an exception on timeout. Added unit test. Author: Chris Egerton <chrise@confluent.io> Reviewers: Magesh Nandakumar <magesh.n.kumar@gmail.com>, Robert Yokota <rayokota@gmail.com>, Arjun Satish <wicknicks@users.noreply.github.com>, Konstantine Karantasis <konstantine@confluent.io>, Randall Hauch <rhauch@gmail.com>, Ewen Cheslack-Postava <ewen@confluent.io> Closes #6384 from C0urante:kafka-8058
- Loading branch information
Showing
4 changed files
with
113 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...me/src/test/java/org/apache/kafka/connect/runtime/health/ConnectClusterStateImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.kafka.connect.runtime.health; | ||
|
||
import org.apache.kafka.connect.errors.ConnectException; | ||
import org.apache.kafka.connect.runtime.Herder; | ||
import org.apache.kafka.connect.runtime.HerderProvider; | ||
import org.apache.kafka.connect.util.Callback; | ||
import org.easymock.Capture; | ||
import org.easymock.EasyMock; | ||
import org.easymock.IAnswer; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.api.easymock.annotation.Mock; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
public class ConnectClusterStateImplTest { | ||
|
||
@Mock | ||
protected Herder herder; | ||
protected HerderProvider herderProvider; | ||
protected ConnectClusterStateImpl connectClusterState; | ||
protected Collection<String> expectedConnectors; | ||
protected long herderRequestTimeoutMs = TimeUnit.SECONDS.toMillis(10); | ||
|
||
@Before | ||
public void setUp() { | ||
herderProvider = new HerderProvider(herder); | ||
connectClusterState = new ConnectClusterStateImpl(herderRequestTimeoutMs, herderProvider); | ||
expectedConnectors = Arrays.asList("sink1", "source1", "source2"); | ||
} | ||
|
||
@Test | ||
public void connectors() { | ||
Capture<Callback<Collection<String>>> callback = EasyMock.newCapture(); | ||
herder.connectors(EasyMock.capture(callback)); | ||
EasyMock.expectLastCall().andAnswer(new IAnswer<Void>() { | ||
@Override | ||
public Void answer() { | ||
callback.getValue().onCompletion(null, expectedConnectors); | ||
return null; | ||
} | ||
}); | ||
EasyMock.replay(herder); | ||
assertEquals(expectedConnectors, connectClusterState.connectors()); | ||
} | ||
|
||
@Test | ||
public void connectorsFailure() { | ||
Capture<Callback<Collection<String>>> callback = EasyMock.newCapture(); | ||
herder.connectors(EasyMock.capture(callback)); | ||
EasyMock.expectLastCall().andAnswer(new IAnswer<Void>() { | ||
@Override | ||
public Void answer() { | ||
Throwable timeout = new TimeoutException(); | ||
callback.getValue().onCompletion(timeout, null); | ||
return null; | ||
} | ||
}); | ||
EasyMock.replay(herder); | ||
assertThrows(ConnectException.class, connectClusterState::connectors); | ||
} | ||
} |