-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Fix bug during initialization of HttpServerInventoryView #14517
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
937d3a3
Fix bug during initialization of HttpServerInventoryView
kfaraz 7f6f3fe
Add tests for coverage
kfaraz 869888c
Merge branch 'master' of github.com:apache/druid into fix_bug_serverview
kfaraz 45bdc8d
Increase coco for WorkerHolder
kfaraz 0094212
Merge branch 'master' of github.com:apache/druid into fix_bug_serverview
kfaraz b8be877
Use separate executor for monitoring tasks
kfaraz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
111 changes: 111 additions & 0 deletions
111
processing/src/main/java/org/apache/druid/java/util/common/Stopwatch.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,111 @@ | ||
/* | ||
* 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.druid.java.util.common; | ||
|
||
import com.google.common.base.Ticker; | ||
import org.joda.time.Duration; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Thread-safe wrapper over {@link com.google.common.base.Stopwatch}. | ||
* <p> | ||
* Thread safety has been limited to the start/stop methods for now as they are | ||
* the only ones that can throw an exception in an illegal state and are thus | ||
* vulnerable to race conditions. | ||
*/ | ||
public class Stopwatch | ||
{ | ||
private final com.google.common.base.Stopwatch delegate; | ||
|
||
public static Stopwatch createStarted() | ||
{ | ||
return new Stopwatch(com.google.common.base.Stopwatch.createStarted()); | ||
} | ||
|
||
public static Stopwatch createUnstarted() | ||
{ | ||
return new Stopwatch(com.google.common.base.Stopwatch.createUnstarted()); | ||
} | ||
|
||
public static Stopwatch createStarted(Ticker ticker) | ||
{ | ||
return new Stopwatch(com.google.common.base.Stopwatch.createStarted(ticker)); | ||
} | ||
|
||
private Stopwatch(com.google.common.base.Stopwatch delegate) | ||
{ | ||
this.delegate = delegate; | ||
} | ||
|
||
public synchronized void start() | ||
{ | ||
delegate.start(); | ||
} | ||
|
||
public synchronized void stop() | ||
{ | ||
delegate.stop(); | ||
} | ||
|
||
public synchronized void reset() | ||
{ | ||
delegate.reset(); | ||
} | ||
|
||
/** | ||
* Invokes {@code reset().start()} on the underlying {@link com.google.common.base.Stopwatch}. | ||
*/ | ||
public synchronized void restart() | ||
{ | ||
delegate.reset().start(); | ||
} | ||
|
||
public synchronized boolean isRunning() | ||
{ | ||
return delegate.isRunning(); | ||
} | ||
|
||
/** | ||
* Returns the milliseconds elapsed on the stopwatch. | ||
*/ | ||
public long millisElapsed() | ||
{ | ||
return delegate.elapsed(TimeUnit.MILLISECONDS); | ||
} | ||
|
||
/** | ||
* Checks if the given duration has already elapsed on the stopwatch. | ||
*/ | ||
public boolean hasElapsed(Duration duration) | ||
{ | ||
return millisElapsed() >= duration.getMillis(); | ||
} | ||
|
||
/** | ||
* Checks that the given duration has not elapsed on the stopwatch. Calling this | ||
* method is the same as {@code !stopwatch.hasElapsed(duration)}. | ||
*/ | ||
public boolean hasNotElapsed(Duration duration) | ||
{ | ||
return !hasElapsed(duration); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
processing/src/test/java/org/apache/druid/java/util/common/StopwatchTest.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,70 @@ | ||
/* | ||
* 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.druid.java.util.common; | ||
|
||
import com.google.common.testing.FakeTicker; | ||
import org.joda.time.Duration; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class StopwatchTest | ||
{ | ||
|
||
@Test | ||
public void testDuplicateStartThrowsException() | ||
{ | ||
Stopwatch stopwatch = Stopwatch.createStarted(); | ||
Assert.assertThrows(IllegalStateException.class, stopwatch::start); | ||
} | ||
|
||
@Test | ||
public void testDuplicateStopThrowsException() | ||
{ | ||
Stopwatch stopwatch = Stopwatch.createUnstarted(); | ||
Assert.assertThrows(IllegalStateException.class, stopwatch::stop); | ||
} | ||
|
||
@Test | ||
public void testMillisElapsed() | ||
{ | ||
FakeTicker fakeTicker = new FakeTicker(); | ||
Stopwatch stopwatch = Stopwatch.createStarted(fakeTicker); | ||
fakeTicker.advance(100, TimeUnit.MILLISECONDS); | ||
stopwatch.stop(); | ||
|
||
Assert.assertEquals(100, stopwatch.millisElapsed()); | ||
} | ||
|
||
@Test | ||
public void testHasElapsed() | ||
{ | ||
FakeTicker fakeTicker = new FakeTicker(); | ||
Stopwatch stopwatch = Stopwatch.createStarted(fakeTicker); | ||
fakeTicker.advance(100, TimeUnit.MILLISECONDS); | ||
stopwatch.stop(); | ||
|
||
Assert.assertTrue(stopwatch.hasElapsed(Duration.millis(50))); | ||
Assert.assertTrue(stopwatch.hasElapsed(Duration.millis(100))); | ||
Assert.assertTrue(stopwatch.hasNotElapsed(Duration.millis(101))); | ||
Assert.assertTrue(stopwatch.hasNotElapsed(Duration.millis(500))); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
Thanks for catching this! Did a bunch of copy-pastes and missed this.