You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2022/07/01 10:10:31 UTC
[brooklyn-server] branch master updated: a few extra tests
This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push:
new b756601d81 a few extra tests
b756601d81 is described below
commit b756601d81f4e4f947a31e1aa389158b31483dc6
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Fri Jul 1 11:10:21 2022 +0100
a few extra tests
---
.../core/mgmt/rebind/RebindEntityTest.java | 30 ++++++++++------
.../util/core/predicates/DslPredicateTest.java | 41 ++++++++++++++++++++++
2 files changed, 61 insertions(+), 10 deletions(-)
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
index a86dd93273..d9bcd86480 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
@@ -291,7 +291,7 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
// Where the same object is referenced from two different fields, using types that do not share a
// super type... then the object will just be deserialized once - at that point it must have *both*
// interfaces.
- @Test(groups="WIP")
+ @Test
public void testHandlesReferencingOtherEntityInPojoFieldsOfOtherTypes() throws Exception {
MyEntityWithMultipleInterfaces origE = origApp.createAndManageChild(EntitySpec.create(MyEntityWithMultipleInterfaces.class));
ReffingEntity reffer = new ReffingEntity();
@@ -784,6 +784,22 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
assertFalse(RebindTestUtils.hasPendingPersists(mgmt()));
}
+ @Test
+ public void testPojoFieldNotRebinded() throws Exception {
+ MyEntity2 my2 = origApp.createAndManageChild(EntitySpec.create(MyEntity2.class));
+ ((MyEntity2Impl) Entities.deproxy(my2)).obj = "hello";
+
+ ((MyEntity2Impl) Entities.deproxy(my2)).requestPersist();
+ //mgmt().getRebindManager().forcePersistNow(true, null);
+
+ TestApplication app2 = rebind();
+ MyEntity2 my2b = (MyEntity2) app2.getChildren().iterator().next();
+
+ // fields not persisted
+ // Asserts.assertEquals( ((MyEntity2Impl) Entities.deproxy(my2b)).obj, "hello");
+ Asserts.assertNull( ((MyEntity2Impl) Entities.deproxy(my2b)).obj);
+ }
+
@Test
public void testCreationWithLambdaFails() throws Exception {
Collection<Entity> oldChildren = MutableList.copyOf( origApp.getChildren() );
@@ -844,7 +860,7 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
public static class MyEntityImpl extends AbstractEntity implements MyEntity {
@SuppressWarnings("unused")
- private final Object dummy = new Object(); // so not serializable
+ private final Object dummy = new Object(); // not a problem that this is not serializable (not written anyway)
public MyEntityImpl() {
}
@@ -874,9 +890,6 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
}
public static class MyEntityWithMultipleInterfacesImpl extends AbstractGroupImpl implements MyEntityWithMultipleInterfaces {
- @SuppressWarnings("unused")
- private final Object dummy = new Object(); // so not serializable
-
public MyEntityWithMultipleInterfacesImpl() {
}
@@ -919,9 +932,6 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
public static final AttributeSensor<Location> LOCATION_REF_SENSOR = new BasicAttributeSensor<Location>(
Location.class, "test.attribute.locationref", "Ref to other location");
- @SuppressWarnings("unused")
- private final Object dummy = new Object(); // so not serializable
-
public MyEntityReffingOthersImpl() {
}
}
@@ -942,8 +952,8 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
public static class MyEntity2Impl extends AbstractEntity implements MyEntity2 {
final List<String> events = new CopyOnWriteArrayList<String>();
- @SuppressWarnings("unused")
- private final Object dummy = new Object(); // so not serializable
+ @SetFromFlag
+ Object obj;
public MyEntity2Impl() {
}
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/predicates/DslPredicateTest.java b/core/src/test/java/org/apache/brooklyn/util/core/predicates/DslPredicateTest.java
index 3de0638d89..ff88c116d0 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/predicates/DslPredicateTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/predicates/DslPredicateTest.java
@@ -22,11 +22,14 @@ import org.apache.brooklyn.core.test.BrooklynMgmtUnitTestSupport;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.flags.TypeCoercions;
import org.apache.brooklyn.util.time.Time;
import org.apache.brooklyn.util.time.Timestamp;
import org.testng.annotations.Test;
+import java.util.Arrays;
+import java.util.Set;
import java.util.function.Predicate;
public class DslPredicateTest extends BrooklynMgmtUnitTestSupport {
@@ -200,6 +203,44 @@ public class DslPredicateTest extends BrooklynMgmtUnitTestSupport {
Asserts.assertFalse(p.test("xa"));
}
+ private static class SetAllowingEqualsToList<T> extends MutableSet<T> {
+ public static <T> SetAllowingEqualsToList<T> of(Iterable<T> items) {
+ SetAllowingEqualsToList<T> result = new SetAllowingEqualsToList<>();
+ result.putAll(items);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof Iterable && !(o instanceof Set)) o = MutableSet.copyOf((Iterable)o);
+ return super.equals(o);
+ }
+ }
+
+ @Test
+ public void testAllWithListWithVariousFlattening() {
+ Asserts.assertTrue(SetAllowingEqualsToList.of(MutableSet.of("y", "x")).equals(MutableList.of("x", "y")));
+
+ DslPredicates.DslPredicate p = TypeCoercions.coerce(MutableMap.of("equals", MutableList.of("x", "y")), DslPredicates.DslPredicate.class);
+ Asserts.assertTrue(p.test(Arrays.asList("x", "y")));
+ // list not equal because of order and equal
+ Asserts.assertFalse(p.test(Arrays.asList("y", "x")));
+ Asserts.assertFalse(p.test(Arrays.asList("x", "y", "z")));
+ // set equality _does_ match without order
+ Asserts.assertTrue(p.test(SetAllowingEqualsToList.of(MutableSet.of("y", "x"))));
+
+ // "all" works because it attempts unflattened at all, then flattens on each test
+ p = TypeCoercions.coerce(MutableMap.of("all", MutableList.of("x", "y")), DslPredicates.DslPredicate.class);
+ Asserts.assertTrue(p.test(Arrays.asList("y", "x")));
+ Asserts.assertTrue(p.test(Arrays.asList("x", "y", "z")));
+ // set equality _does_ match!
+ Asserts.assertTrue(p.test(SetAllowingEqualsToList.of(MutableSet.of("y", "x"))));
+
+ // specify unflattening also works, but is unnecessary
+ p = TypeCoercions.coerce(MutableMap.of("unflattened", MutableMap.of("all", MutableList.of("x", "y"))), DslPredicates.DslPredicate.class);
+ Asserts.assertTrue(p.test(Arrays.asList("x", "y", "z")));
+ }
+
@Test
public void testLocationTagImplicitEquals() {
DslPredicates.DslPredicate p = TypeCoercions.coerce(MutableMap.of(