rpuch commented on a change in pull request #694:
URL: https://github.com/apache/ignite-3/pull/694#discussion_r816497382
##########
File path:
modules/configuration/src/test/java/org/apache/ignite/internal/configuration/testframework/ConfigurationExtension.java
##########
@@ -255,27 +292,79 @@ public long notificationCount() {
return cfgRef.get();
}
- /**
- * Looks for the annotated field inside the given test class.
- *
- * @return Annotated fields.
- */
- private static List<Field> getMatchingFields(Class<?> testClass) {
+ private static List<Field> getInjectConfigurationFields(Class<?>
testClass) {
return AnnotationSupport.findAnnotatedFields(
testClass,
InjectConfiguration.class,
- field -> supportType(field.getType()),
+ field -> isNameEndsWithConfiguration(field.getType()),
HierarchyTraversalMode.TOP_DOWN
);
}
+ private static List<Field> getInjectRevisionListenerHolderFields(Class<?>
testClass) {
+ return AnnotationSupport.findAnnotatedFields(
+ testClass,
+ InjectRevisionListenerHolder.class,
+ field -> isRevisionListenerHolder(field.getType()),
+ HierarchyTraversalMode.TOP_DOWN
+ );
+ }
+
+ private static boolean isNameEndsWithConfiguration(Class<?> type) {
+ return type.getCanonicalName().endsWith("Configuration");
+ }
+
+ private static boolean isRevisionListenerHolder(Class<?> type) {
+ return
ConfigurationStorageRevisionListenerHolder.class.isAssignableFrom(type);
+ }
+
/**
- * Checks that instance of the given class can be injected by the
extension.
- *
- * @param type Field or parameter type.
- * @return {@code true} if value of the given class can be injected.
+ * Implementation for {@link ConfigurationExtension}.
*/
- private static boolean supportType(Class<?> type) {
- return type.getCanonicalName().endsWith("Configuration");
+ private static class StorageRevisionListenerHolderImpl implements
ConfigurationStorageRevisionListenerHolder {
+ final AtomicLong storageRev = new AtomicLong();
+
+ final AtomicLong notificationListenerCnt = new AtomicLong();
+
+ final
ConfigurationListenerHolder<ConfigurationStorageRevisionListener> listeners =
new ConfigurationListenerHolder<>();
+
+ /** {@inheritDoc} */
+ @Override
+ public void
listenUpdateStorageRevision(ConfigurationStorageRevisionListener listener) {
+ listeners.addListener(listener, notificationListenerCnt.get());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void
stopListenUpdateStorageRevision(ConfigurationStorageRevisionListener listener) {
+ listeners.removeListener(listener);
+ }
+
+ private Collection<CompletableFuture<?>>
notifyStorageRevisionListeners(long storageRevision, long notificationNumber) {
+ // Lazy init.
+ List<CompletableFuture<?>> futures = null;
Review comment:
Does a test class need to try avoiding an allocation? It seems that the
performance is not important here, but this trick complicates the code a little.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]