-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9375 Add thread names to kafka connect #7901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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.common.utils; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.concurrent.ThreadFactory; | ||
|
|
||
| public class ThreadUtilsTest { | ||
|
|
||
| private static final Runnable EMPTY_RUNNABLE = new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| } | ||
| }; | ||
| private static final String THREAD_NAME = "ThreadName"; | ||
| private static final String THREAD_NAME_WITH_NUMBER = THREAD_NAME + "%d"; | ||
|
|
||
|
|
||
| @Test | ||
| public void testThreadNameWithoutNumberNoDemon() { | ||
| Assert.assertEquals(ThreadUtils.createThreadFactory(THREAD_NAME, false). | ||
| newThread(EMPTY_RUNNABLE).getName(), THREAD_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void testThreadNameWithoutNumberDemon() { | ||
| Thread daemonThread = ThreadUtils.createThreadFactory(THREAD_NAME, true).newThread(EMPTY_RUNNABLE); | ||
| try { | ||
| Assert.assertEquals(daemonThread.getName(), THREAD_NAME); | ||
| Assert.assertTrue(daemonThread.isDaemon()); | ||
| } finally { | ||
| try { | ||
| daemonThread.join(); | ||
| } catch (InterruptedException e) { | ||
| // can be ignored | ||
| e.printStackTrace(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we don't need to print the stack trace if we can ignore it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Will do that |
||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testThreadNameWithNumberNoDemon() { | ||
| ThreadFactory localThreadFactory = ThreadUtils.createThreadFactory(THREAD_NAME_WITH_NUMBER, false); | ||
| Assert.assertEquals(localThreadFactory.newThread(EMPTY_RUNNABLE).getName(), THREAD_NAME + "1"); | ||
| Assert.assertEquals(localThreadFactory.newThread(EMPTY_RUNNABLE).getName(), THREAD_NAME + "2"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testThreadNameWithNumberDemon() { | ||
| ThreadFactory localThreadFactory = ThreadUtils.createThreadFactory(THREAD_NAME_WITH_NUMBER, true); | ||
| Thread daemonThread1 = localThreadFactory.newThread(EMPTY_RUNNABLE); | ||
| Thread daemonThread2 = localThreadFactory.newThread(EMPTY_RUNNABLE); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to check if 2 daemonThreads are appropriately numbered. |
||
|
|
||
| try { | ||
| Assert.assertEquals(daemonThread1.getName(), THREAD_NAME + "1"); | ||
| Assert.assertTrue(daemonThread1.isDaemon()); | ||
| } finally { | ||
| try { | ||
| daemonThread1.join(); | ||
| } catch (InterruptedException e) { | ||
| // can be ignored | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| try { | ||
| Assert.assertEquals(daemonThread2.getName(), THREAD_NAME + "2"); | ||
| Assert.assertTrue(daemonThread2.isDaemon()); | ||
| } finally { | ||
| try { | ||
| daemonThread2.join(); | ||
| } catch (InterruptedException e) { | ||
| // can be ignored | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import org.apache.kafka.connect.util.Callback; | ||
| import org.easymock.EasyMock; | ||
| import org.junit.After; | ||
| import org.junit.Assert; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we import static like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.powermock.api.easymock.PowerMock; | ||
|
|
@@ -30,6 +31,7 @@ | |
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ThreadPoolExecutor; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
|
|
@@ -41,6 +43,11 @@ public class FileOffsetBackingStoreTest { | |
| File tempFile; | ||
|
|
||
| private static Map<ByteBuffer, ByteBuffer> firstSet = new HashMap<>(); | ||
| private static final Runnable EMPTY_RUNNABLE = new Runnable() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you can use the Java 8 syntax:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do that |
||
| @Override | ||
| public void run() { | ||
| } | ||
| }; | ||
|
|
||
| static { | ||
| firstSet.put(buffer("key"), buffer("value")); | ||
|
|
@@ -100,6 +107,12 @@ public void testSaveRestore() throws Exception { | |
| PowerMock.verifyAll(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testThreadName() { | ||
| Assert.assertTrue(((ThreadPoolExecutor) store.executor).getThreadFactory() | ||
| .newThread(EMPTY_RUNNABLE).getName().startsWith(FileOffsetBackingStore.class.getSimpleName())); | ||
| } | ||
|
|
||
| private static ByteBuffer buffer(String v) { | ||
| return ByteBuffer.wrap(v.getBytes()); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all
assertmethod, the first argument is the "expected" value while the second one is the "actual" value. Can you swap them in this file to match that definition?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
acked