core: fix Attributes value equality

Fixes: #3857
This commit is contained in:
Carl Mastrangelo 2017-12-11 18:12:49 -08:00 committed by GitHub
parent 2ea77cce1e
commit 1bb9498ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -129,7 +129,18 @@ public final class Attributes {
return false; return false;
} }
Attributes that = (Attributes) o; Attributes that = (Attributes) o;
return Objects.equal(data, that.data); if (data.size() != that.data.size()) {
return false;
}
for (Entry<Key<?>, Object> e : data.entrySet()) {
if (!that.data.containsKey(e.getKey())) {
return false;
}
if (!Objects.equal(e.getValue(), that.data.get(e.getKey()))) {
return false;
}
}
return true;
} }
/** /**

View File

@ -17,6 +17,7 @@
package io.grpc; package io.grpc;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import org.junit.Test; import org.junit.Test;
@ -50,4 +51,20 @@ public class AttributesTest {
public void empty() { public void empty() {
assertEquals(0, Attributes.EMPTY.keys().size()); assertEquals(0, Attributes.EMPTY.keys().size());
} }
@Test
@SuppressWarnings("BoxedPrimitiveConstructor")
public void valueEquality() {
Attributes.Key<Integer> key = Attributes.Key.of("ints");
Integer v1 = new Integer(100000);
Integer v2 = new Integer(100000);
assertNotSame(v1, v2);
assertEquals(v1, v2);
Attributes attr1 = Attributes.newBuilder().set(key, v1).build();
Attributes attr2 = Attributes.newBuilder().set(key, v2).build();
assertEquals(attr1, attr2);
}
} }