Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Change all DirectExecutors to use a SystemExecutor and fix servi…
…ce shutdowns (#744) Also deflake the world so all tests run 100 times in a row successfully even with the new executors, and centralize alarm creation to fix polling test bugs due to scheduleAtFixedRate and test flakiness.
- Loading branch information
1 parent
245004e
commit c8541aa
Showing
38 changed files
with
425 additions
and
316 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
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
50 changes: 50 additions & 0 deletions
50
google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/internal/AlarmFactory.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,50 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed 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 com.google.cloud.pubsublite.internal; | ||
|
||
import static java.util.concurrent.TimeUnit.NANOSECONDS; | ||
|
||
import com.google.cloud.pubsublite.internal.wire.SystemExecutors; | ||
import com.google.common.flogger.GoogleLogger; | ||
import java.time.Duration; | ||
import java.util.concurrent.Future; | ||
|
||
// An alarm factory comes with a builtin delay and constructs a future which runs that delay after | ||
// it finishes. | ||
public interface AlarmFactory { | ||
Future<?> newAlarm(Runnable runnable); | ||
|
||
// Get around lack of interface support for private static members in java 8 | ||
final class Internal { | ||
private static final GoogleLogger LOGGER = GoogleLogger.forEnclosingClass(); | ||
}; | ||
|
||
static AlarmFactory create(Duration duration) { | ||
return runnable -> | ||
SystemExecutors.getAlarmExecutor() | ||
.scheduleWithFixedDelay( | ||
() -> { | ||
try { | ||
runnable.run(); | ||
} catch (Throwable t) { | ||
Internal.LOGGER.atSevere().withCause(t).log("Alarm leaked exception."); | ||
} | ||
}, | ||
0, | ||
duration.toNanos(), | ||
NANOSECONDS); | ||
} | ||
} |
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
Oops, something went wrong.