Skip to content

Commit

Permalink
Delete wait async batch (#174)
Browse files Browse the repository at this point in the history
## Description

Wait async when deletion resources.

During experiments with streams-e2e I was able to save more then `3min`
(per test) when I had to delete all operators etc...

I also changed log4j2.properties to log thread ID instead of name to do
not mess log output.

## Type of Change

Please delete options that are not relevant.

* New feature (non-breaking change which adds functionality)

## Checklist

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit/integration tests pass locally with my
changes

Signed-off-by: David Kornel <[email protected]>
  • Loading branch information
kornys authored Aug 28, 2024
1 parent 3810044 commit 35181c2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,20 +372,23 @@ private <T extends HasMetadata> void createOrUpdateResource(boolean async,
*/
@SafeVarargs
public final <T extends HasMetadata> void deleteResource(T... resources) {
List<CompletableFuture<Void>> waitExecutors = new LinkedList<>();
for (T resource : resources) {
ResourceType<T> type = findResourceType(resource);
LoggerUtils.logResource("Deleting", resource);
try {
if (type == null) {
client.getClient().resource(resource).delete();
assertTrue(waitResourceCondition(resource, ResourceCondition.deletion()),
String.format("Timed out deleting %s/%s in %s", resource.getKind(),
resource.getMetadata().getName(), resource.getMetadata().getNamespace()));
waitExecutors.add(CompletableFuture.runAsync(() ->
assertTrue(waitResourceCondition(resource, ResourceCondition.deletion()),
String.format("Timed out deleting %s/%s in %s", resource.getKind(),
resource.getMetadata().getName(), resource.getMetadata().getNamespace()))));
} else {
type.delete(resource);
assertTrue(waitResourceCondition(resource, ResourceCondition.deletion()),
String.format("Timed out deleting %s/%s in %s", resource.getKind(),
resource.getMetadata().getName(), resource.getMetadata().getNamespace()));
waitExecutors.add(CompletableFuture.runAsync(() ->
assertTrue(waitResourceCondition(resource, ResourceCondition.deletion()),
String.format("Timed out deleting %s/%s in %s", resource.getKind(),
resource.getMetadata().getName(), resource.getMetadata().getNamespace()))));
}
} catch (Exception e) {
if (resource.getMetadata().getNamespace() == null) {
Expand All @@ -396,6 +399,9 @@ public final <T extends HasMetadata> void deleteResource(T... resources) {
resource.getMetadata().getName(), resource.getMetadata().getNamespace(), e);
}
}
if (!waitExecutors.isEmpty()) {
CompletableFuture.allOf(waitExecutors.toArray(new CompletableFuture[0])).join();
}
deleteCallbacks.forEach(callback -> callback.accept(resource));
}
}
Expand Down Expand Up @@ -474,12 +480,18 @@ public void deleteResources() {
new AtomicInteger(0);
while (STORED_RESOURCES.containsKey(getTestContext().getDisplayName()) && numberOfResources.get() > 0) {
Stack<ResourceItem<?>> s = STORED_RESOURCES.get(getTestContext().getDisplayName());

List<CompletableFuture<Void>> waitExecutors = new LinkedList<>();
while (!s.isEmpty()) {
ResourceItem<?> resourceItem = s.pop();

try {
resourceItem.throwableRunner().run();
waitExecutors.add(CompletableFuture.runAsync(() -> {
try {
resourceItem.throwableRunner().run();
} catch (Exception e) {
throw new RuntimeException(e);
}
}));
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
Expand All @@ -490,6 +502,9 @@ public void deleteResources() {
}
});
}
if (!waitExecutors.isEmpty()) {
CompletableFuture.allOf(waitExecutors.toArray(new CompletableFuture[0])).join();
}
}
STORED_RESOURCES.remove(getTestContext().getDisplayName());
LoggerUtils.logSeparator();
Expand Down
2 changes: 1 addition & 1 deletion test-frame-common/src/main/resources/log4j2.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = TFConfig
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss}{GMT} [%thread] %highlight{%-5p} [%c{1}:%L] %m%n
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss}{GMT} [%tid] %highlight{%-5p} [%c{1}:%L] %m%n

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = LCConfig
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss}{GMT} [%thread] %highlight{%-5p} [%c{1}:%L] %m%n
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss}{GMT} [%tid] %highlight{%-5p} [%c{1}:%L] %m%n

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = MCConfig
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss}{GMT} [%thread] %highlight{%-5p} [%c{1}:%L] %m%n
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss}{GMT} [%tid] %highlight{%-5p} [%c{1}:%L] %m%n

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
Expand Down

0 comments on commit 35181c2

Please sign in to comment.