-
Notifications
You must be signed in to change notification settings - Fork 51
fix: context serialization missing props (with revert) #1768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,13 +4,10 @@ | |||||
| import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||||||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||||||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||||||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||||||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||
|
|
||||||
| import java.util.Arrays; | ||||||
| import java.util.Collections; | ||||||
| import java.util.HashMap; | ||||||
| import java.util.HashSet; | ||||||
| import java.util.Map; | ||||||
| import org.junit.jupiter.api.DisplayName; | ||||||
| import org.junit.jupiter.api.Test; | ||||||
|
|
@@ -53,7 +50,7 @@ void shouldChangeTargetingKeyFromOverridingContext() { | |||||
| assertEquals("overriding_key", merge.getTargetingKey()); | ||||||
| } | ||||||
|
|
||||||
| @DisplayName("targeting key should not be changed from the overriding context if missing") | ||||||
| @DisplayName("targeting key should not changed from the overriding context if missing") | ||||||
| @Test | ||||||
| void shouldRetainTargetingKeyWhenOverridingContextTargetingKeyValueIsEmpty() { | ||||||
| HashMap<String, Value> attributes = new HashMap<>(); | ||||||
|
|
@@ -69,7 +66,7 @@ void shouldRetainTargetingKeyWhenOverridingContextTargetingKeyValueIsEmpty() { | |||||
| @Test | ||||||
| void missingTargetingKeyShould() { | ||||||
| EvaluationContext ctx = new ImmutableContext(); | ||||||
| assertNull(ctx.getTargetingKey()); | ||||||
| assertEquals(null, ctx.getTargetingKey()); | ||||||
| } | ||||||
|
|
||||||
| @DisplayName("Merge should retain all the attributes from the existing context when overriding context is null") | ||||||
|
|
@@ -148,26 +145,10 @@ void mergeShouldObtainKeysFromOverridingContextWhenExistingContextIsEmpty() { | |||||
| EvaluationContext ctx = new ImmutableContext(); | ||||||
| EvaluationContext overriding = new ImmutableContext(attributes); | ||||||
| EvaluationContext merge = ctx.merge(overriding); | ||||||
| assertEquals(new HashSet<>(Arrays.asList("key1", "key2")), merge.keySet()); | ||||||
| assertEquals(new java.util.HashSet<>(java.util.Arrays.asList("key1", "key2")), merge.keySet()); | ||||||
| } | ||||||
|
|
||||||
| @DisplayName("Two ImmutableContext objects with identical attributes are considered equal") | ||||||
| @Test | ||||||
| void testImmutableContextEquality() { | ||||||
| Map<String, Value> map1 = new HashMap<>(); | ||||||
| map1.put("key", new Value("value")); | ||||||
|
|
||||||
| Map<String, Value> map2 = new HashMap<>(); | ||||||
| map2.put("key", new Value("value")); | ||||||
|
|
||||||
| ImmutableContext a = new ImmutableContext(null, map1); | ||||||
| ImmutableContext b = new ImmutableContext(null, map2); | ||||||
|
|
||||||
| assertEquals(a, b); | ||||||
| assertEquals(a.hashCode(), b.hashCode()); | ||||||
| } | ||||||
|
|
||||||
| @DisplayName("Two different ImmutableContext objects with different contents are not considered equal") | ||||||
| @DisplayName("Two different MutableContext objects with the different contents are not considered equal") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The display name for this test seems to have a copy-paste error, as it refers to
Suggested change
|
||||||
| @Test | ||||||
| void unequalImmutableContextsAreNotEqual() { | ||||||
| final Map<String, Value> attributes = new HashMap<>(); | ||||||
|
|
@@ -180,16 +161,17 @@ void unequalImmutableContextsAreNotEqual() { | |||||
| assertNotEquals(ctx, ctx2); | ||||||
| } | ||||||
|
|
||||||
| @DisplayName("ImmutableContext hashCode is stable across multiple invocations") | ||||||
| @DisplayName("Two different MutableContext objects with the same content are considered equal") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The display name for this test incorrectly refers to
Suggested change
|
||||||
| @Test | ||||||
| void immutableContextHashCodeIsStable() { | ||||||
| Map<String, Value> map = new HashMap<>(); | ||||||
| map.put("key", new Value("value")); | ||||||
| void equalImmutableContextsAreEqual() { | ||||||
| final Map<String, Value> attributes = new HashMap<>(); | ||||||
| attributes.put("key1", new Value("val1")); | ||||||
| final ImmutableContext ctx = new ImmutableContext(attributes); | ||||||
|
|
||||||
| ImmutableContext ctx = new ImmutableContext(null, map); | ||||||
| final Map<String, Value> attributes2 = new HashMap<>(); | ||||||
| attributes2.put("key1", new Value("val1")); | ||||||
| final ImmutableContext ctx2 = new ImmutableContext(attributes2); | ||||||
|
|
||||||
| int first = ctx.hashCode(); | ||||||
| int second = ctx.hashCode(); | ||||||
| assertEquals(first, second); | ||||||
| assertEquals(ctx, ctx2); | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
equals()andhashCode()methods have been removed from this class. This reverts toObject's identity-based equality, which is inconsistent with otherEvaluationContextimplementations likeImmutableContextandMutableContextthat provide value-based equality. This is a significant behavioral change that could break consumers relying on value comparison (e.g., in collections).If this was an unintended side-effect of removing the caching logic, please consider re-implementing
equals()andhashCode()to restore value semantics, for example by delegating toasMap(). Without this,LayeredEvaluationContextwill not behave as expected in HashMaps or other collections that rely onequals.