The following JUnit test fails, but shouldn't:
@Test
public void testFoo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
DefaultOpEnvironment defOpEnv = getDefaultOpEnv();
// Put the Op in the cache
Producer<String> foo = defOpEnv.op("test.basicOp").input().outType(String.class).producer();
// Call the Op a different way, but with the same args -> should be a cache hit
Nil<Producer<String>> specialType = new Nil<>() {};
Nil<String> outType = Nil.of(String.class);
Producer<String> bar = defOpEnv.op("test.basicOp", specialType, new Nil[] {}, outType);
// Assert only one cache entry
Map<MatchingConditions, OpInstance> opCache = getOpCache(defOpEnv);
Assert.assertEquals(1, opCache.size());
}
This breaks because the MatchingConditions of the two calls return different hashCodes, due to the differences in the underlying OpRef. These differences are due to the ParameterizedType implementations used to create the specialType:
- The first (i.e.
OpBuilder) method calls the TypeService under the hood. This results in a Types.TypeUtils.ParameterizedTypeImpl under the hood.
- The second method uses a
Types.ParameterizedTypeImpl (from Guava) under the hood.
As these implementations of ParameterizedType produce their hashcodes differently, the resulting DefaultOpRefs have different hashcodes.
The following JUnit test fails, but shouldn't:
This breaks because the
MatchingConditionsof the two calls return differenthashCodes, due to the differences in the underlyingOpRef. These differences are due to theParameterizedTypeimplementations used to create thespecialType:OpBuilder) method calls theTypeServiceunder the hood. This results in aTypes.TypeUtils.ParameterizedTypeImplunder the hood.Types.ParameterizedTypeImpl(from Guava) under the hood.As these implementations of
ParameterizedTypeproduce their hashcodes differently, the resultingDefaultOpRefs have different hashcodes.