From 7a67c1f1a3eb12673e151de4db63b1a183b5339d Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 14 Jul 2017 16:31:46 -0400 Subject: [PATCH] Various polishing and optimizations * Check for `null` package in the `JacksonJsonUtils`. Also don't call `this.delegate.typeFromId()` the second time * Increase wait timeout in the `QueueChannelTests` * Check `ZookeeperMetadataStore.addListener()` for `null` **Cherry-pick to 4.3.x** --- .../integration/support/json/JacksonJsonUtils.java | 6 +++--- .../integration/channel/QueueChannelTests.java | 4 ++-- .../zookeeper/metadata/ZookeeperMetadataStore.java | 10 ++++++---- .../metadata/ZookeeperMetadataStoreTests.java | 14 +++++++++++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java index 5f4ffdc6fe..58930635e2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java @@ -196,9 +196,9 @@ public final class JacksonJsonUtils { DeserializationConfig config = (DeserializationConfig) context.getConfig(); JavaType result = this.delegate.typeFromId(context, id); - String packageName = result.getRawClass().getPackage().getName(); - if (isTrustedPackage(packageName)) { - return this.delegate.typeFromId(context, id); + Package aPackage = result.getRawClass().getPackage(); + if (aPackage == null || isTrustedPackage(aPackage.getName())) { + return result; } boolean isExplicitMixin = config.findMixInClassFor(result.getRawClass()) != null; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/QueueChannelTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/QueueChannelTests.java index efb5b2e211..80c9c1e033 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/QueueChannelTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/QueueChannelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ public class QueueChannelTests { }).start(); assertFalse(messageReceived.get()); channel.send(new GenericMessage("testing")); - latch.await(1000, TimeUnit.MILLISECONDS); + latch.await(10000, TimeUnit.MILLISECONDS); assertTrue(messageReceived.get()); } diff --git a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java index 933120ea2b..cea0a0be40 100644 --- a/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java +++ b/spring-integration-zookeeper/src/main/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStore.java @@ -37,12 +37,13 @@ import org.springframework.integration.support.utils.IntegrationUtils; import org.springframework.util.Assert; /** - * Zookeeper-based {@link ListenableMetadataStore} based on a Zookeeper node. Values are stored in the children node, - * the names of which are stored as keys. + * Zookeeper-based {@link ListenableMetadataStore} based on a Zookeeper node. + * Values are stored in the children node, the names of which are stored as keys. * * @author Marius Bogoevici * @author Gary Russell * @author Artem Bilan + * * @since 4.2 */ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLifecycle { @@ -164,8 +165,9 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif } @Override - public void addListener(MetadataStoreListener callback) { - this.listeners.add(callback); + public void addListener(MetadataStoreListener listener) { + Assert.notNull(listener, "'listener' must not be null"); + this.listeners.add(listener); } @Override diff --git a/spring-integration-zookeeper/src/test/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStoreTests.java b/spring-integration-zookeeper/src/test/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStoreTests.java index 4471d2ffb4..680505d2c6 100644 --- a/spring-integration-zookeeper/src/test/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStoreTests.java +++ b/spring-integration-zookeeper/src/test/java/org/springframework/integration/zookeeper/metadata/ZookeeperMetadataStoreTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.integration.zookeeper.metadata; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -50,6 +52,8 @@ import org.springframework.integration.zookeeper.ZookeeperTestSupport; /** * @author Marius Bogoevici + * @author Artem Bilan + * * @since 4.2 */ public class ZookeeperMetadataStoreTests extends ZookeeperTestSupport { @@ -233,6 +237,14 @@ public class ZookeeperMetadataStoreTests extends ZookeeperTestSupport { barriers.put("add", new CyclicBarrier(2)); barriers.put("remove", new CyclicBarrier(2)); barriers.put("update", new CyclicBarrier(2)); + try { + metadataStore.addListener(null); + fail("IllegalArgumentException expected"); + } + catch (Exception e) { + assertThat(e, instanceOf(IllegalArgumentException.class)); + assertThat(e.getMessage(), containsString("'listener' must not be null")); + } metadataStore.addListener(new MetadataStoreListenerAdapter() { @Override public void onAdd(String key, String value) {