Skip to content

Commit

Permalink
Merge pull request google#815 from google/moe_writing_branch_from_76b…
Browse files Browse the repository at this point in the history
…e88e8140f77a25824f5deb67bb13b8e5dabc6

Merge internal changes: flake fixes, codesite->github, optionalbinder fix
  • Loading branch information
sameb committed Jul 10, 2014
2 parents 0ec824f + 0558b32 commit 0c27536
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 270 deletions.
6 changes: 3 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@
docletpath="${jdiff.home}/jdiff.jar${path.separator}${jdiff.home}/xerces.jar"
maxmemory="512M"
sourcefiles="${jdiff.home}/Null.java"
classpath="lib/javax.inject.jar${path.separator}lib/aopalliance.jar${path.separator}lib/guava-16.0.1.jar">
classpath="lib/javax.inject.jar${path.separator}lib/aopalliance.jar${path.separator}lib/guava-16.0.1.jar">
<doclet name="jdiff.JDiff">
<param name="-oldapi" value="${old.api}"/>
<param name="-oldapidir" value="latest-api-diffs"/>
<param name="-oldapidir" value="latest-api-diffs"/>
<param name="-javadocold" value="http://google.github.io/guice/api-docs/${old.api}/javadoc/"/>
<param name="-newapi" value="${new.api}"/>
<param name="-newapidir" value="${jdiff.tmp}"/>
Expand Down Expand Up @@ -286,5 +286,5 @@
<ant dir="extensions/grapher" antfile="build.xml" target="clean"/>
<ant dir="extensions/testlib" antfile="build.xml" target="clean"/>
</target>

</project>
4 changes: 2 additions & 2 deletions common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<property name="Bundle-SymbolicName" value="${module}"/>
<property name="Bundle-Version" value="${replace;${version};^[^0-9];0.0.0.$0}"/>

<property name="Bundle-Description" value="Guice is a lightweight dependency injection framework for Java 5 and above"/>
<property name="Bundle-DocURL" value="http://code.google.com/p/google-guice/"/>
<property name="Bundle-Description" value="Guice is a lightweight dependency injection framework for Java 6 and above"/>
<property name="Bundle-DocURL" value="https://github.com/google/guice"/>
<property name="Bundle-Copyright" value="Copyright (C) 2006 Google Inc."/>
<property name="Bundle-License" value="http://www.apache.org/licenses/LICENSE-2.0.txt"/>
<property name="Bundle-RequiredExecutionEnvironment" value="JavaSE-1.6"/>
Expand Down
4 changes: 2 additions & 2 deletions core/test/com/google/inject/BinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ protected void configure() {

/**
* See issue 614, Problem One
* http://code.google.com/p/google-guice/issues/detail?id=614
* https://github.com/google/guice/issues/614
*/
public void testJitDependencyDoesntBlockOtherExplicitBindings() {
Injector injector = Guice.createInjector(new AbstractModule() {
Expand All @@ -377,7 +377,7 @@ protected void configure() {

/**
* See issue 614, Problem Two
* http://code.google.com/p/google-guice/issues/detail?id=614
* https://github.com/google/guice/issues/id=614
*/
public void testJitDependencyCanUseExplicitDependencies() {
Guice.createInjector(new AbstractModule() {
Expand Down
2 changes: 1 addition & 1 deletion core/test/com/google/inject/ImplicitBindingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static class JitValid { @Inject JitValid2 a; }
static class JitValid2 {}

/**
* Regression test for http://code.google.com/p/google-guice/issues/detail?id=319
* Regression test for https://github.com/google/guice/issues/319
*
* The bug is that a class that asks for a provider for itself during injection time,
* where any one of the other types required to fulfill the object creation was bound
Expand Down
172 changes: 40 additions & 132 deletions core/test/com/google/inject/internal/WeakKeySetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

package com.google.inject.internal;

import static com.google.inject.internal.WeakKeySetUtils.assertBlacklisted;
import static com.google.inject.internal.WeakKeySetUtils.assertInSet;
import static com.google.inject.internal.WeakKeySetUtils.assertNotBlacklisted;
import static com.google.inject.internal.WeakKeySetUtils.assertNotInSet;
import static com.google.inject.internal.WeakKeySetUtils.assertSourceNotInSet;
import static com.google.inject.internal.WeakKeySetUtils.awaitClear;
import static com.google.inject.internal.WeakKeySetUtils.awaitFullGc;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -64,44 +72,6 @@ public class WeakKeySetTest extends TestCase {
protected void setUp() throws Exception {
set = new WeakKeySet(new Object());
}

private static void awaitFullGc() {
// GcFinalization *should* do it, but doesn't work well in practice...
// so we put a second latch and wait for a ReferenceQueue to tell us.
ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
WeakReference ref = new WeakReference<Object>(new Object(), queue);
GcFinalization.awaitFullGc();
try {
assertSame("queue didn't return ref in time", ref, queue.remove(5000));
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

private static void awaitClear(WeakReference<?> ref) {
// GcFinalization *should* do it, but doesn't work well in practice...
// so we put a second latch and wait for a ReferenceQueue to tell us.
Object data = ref.get();
ReferenceQueue<Object> queue = null;
WeakReference extraRef = null;
if (data != null) {
queue = new ReferenceQueue<Object>();
extraRef = new WeakReference<Object>(data, queue);
data = null;
}
GcFinalization.awaitClear(ref);
if (queue != null) {
try {
assertSame("queue didn't return ref in time", extraRef, queue.remove(5000));
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}

public void testEviction() {
TestState state = new TestState();
Expand All @@ -111,16 +81,13 @@ public void testEviction() {
WeakReference<Key<Integer>> weakKeyRef = new WeakReference<Key<Integer>>(key);

set.add(key, state, source);
assertTrue(set.contains(key));
assertEquals(1, set.getSources(key).size());
assertTrue(set.getSources(key).contains(source));
assertInSet(set, key, 1, source);

state = null;

awaitFullGc();

assertFalse(set.contains(Key.get(Integer.class)));
assertNull(set.getSources(Key.get(Integer.class)));
assertNotInSet(set, Key.get(Integer.class));

// Ensure there are no hanging references.
key = null;
Expand All @@ -135,16 +102,13 @@ public void testEviction_nullSource() {
WeakReference<Key<Integer>> weakKeyRef = new WeakReference<Key<Integer>>(key);

set.add(key, state, source);
assertTrue(set.contains(key));
assertEquals(1, set.getSources(key).size());
assertTrue(set.getSources(key).contains(source));
assertInSet(set, key, 1, source);

state = null;

awaitFullGc();

assertFalse(set.contains(Key.get(Integer.class)));
assertNull(set.getSources(Key.get(Integer.class)));
assertNotInSet(set, Key.get(Integer.class));

// Ensure there are no hanging references.
key = null;
Expand All @@ -160,14 +124,10 @@ public void testEviction_keyOverlap_2x() {
Object source2 = new Object();

set.add(key1, state1, source1);
assertTrue(set.contains(key1));
assertEquals(1, set.getSources(key1).size());
assertTrue(set.getSources(key1).contains(source1));
assertInSet(set, key1, 1, source1);

set.add(key2, state2, source2);
assertTrue(set.contains(key2));
assertEquals(2, set.getSources(key2).size());
assertTrue(set.getSources(key2).containsAll(Arrays.asList(source1, source2)));
assertInSet(set, key2, 2, source1, source2);

WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
Expand All @@ -179,10 +139,8 @@ public void testEviction_keyOverlap_2x() {

awaitFullGc();

assertTrue(set.contains(key));
assertEquals(1, set.getSources(key).size());
assertTrue(set.getSources(key).contains(source2));
assertFalse(set.getSources(key).contains(source1));
assertSourceNotInSet(set, key, source1);
assertInSet(set, key, 1, source2);

source1 = source2 = null;

Expand All @@ -197,8 +155,7 @@ public void testEviction_keyOverlap_2x() {

awaitFullGc();

assertFalse(set.contains(key));
assertNull(set.getSources(key));
assertNotInSet(set, key);

awaitClear(weakKey2Ref);
awaitClear(weakSource2Ref);
Expand All @@ -215,25 +172,18 @@ public void testNoEviction_keyOverlap_2x() {
Object source2 = new Object();

set.add(key1, state1, source1);
assertTrue(set.contains(key1));
assertEquals(1, set.getSources(key1).size());
assertTrue(set.getSources(key1).contains(source1));
assertInSet(set, key1, 1, source1);

set.add(key2, state2, source2);
assertTrue(set.contains(key2));
assertEquals(2, set.getSources(key2).size());
assertTrue(set.getSources(key1).containsAll(Arrays.asList(source1, source2)));
assertInSet(set, key2, 2, source1, source2);

WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);

Key<Integer> key = key1 = key2 = Key.get(Integer.class);

awaitFullGc();

assertTrue(set.contains(key));
assertEquals(2, set.getSources(key).size());
assertTrue(set.getSources(key1).containsAll(Arrays.asList(source1, source2)));
assertInSet(set, key, 2, source1, source2);

// Ensure the keys don't get GC'd when states are still referenced. key1 will be present in the
// as the map key but key2 could be GC'd if the implementation does something wrong.
Expand All @@ -249,16 +199,12 @@ public void testEviction_keyAndSourceOverlap_null() {
Object source = null;

set.add(key1, state1, source);
assertTrue(set.contains(key1));
assertEquals(1, set.getSources(key1).size());
assertTrue(set.getSources(key1).contains(source));
assertInSet(set, key1, 1, source);

set.add(key2, state2, source);
assertTrue(set.contains(key2));

// Same source so still only one value.
assertEquals(1, set.getSources(key2).size());
assertTrue(set.getSources(key1).contains(source));
assertInSet(set, key2, 1, source);
assertInSet(set, key1, 1, source);

WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
Expand All @@ -268,13 +214,9 @@ public void testEviction_keyAndSourceOverlap_null() {
state1 = null;

awaitFullGc();

assertTrue(set.contains(key));

// Should still have a single source.
assertEquals(1, set.getSources(key).size());
assertTrue(set.getSources(key1).contains(source));

assertInSet(set, key, 1, source);

source = null;

awaitClear(weakSourceRef);
Expand All @@ -284,9 +226,7 @@ public void testEviction_keyAndSourceOverlap_null() {
state2 = null;

awaitFullGc();

assertFalse(set.contains(key));
assertNull(set.getSources(key));
assertNotInSet(set, key);

awaitClear(weakKey2Ref);
awaitClear(weakSourceRef);
Expand All @@ -302,16 +242,11 @@ public void testEviction_keyAndSourceOverlap_nonNull() {
Object source = new Object();

set.add(key1, state1, source);
assertTrue(set.contains(key1));
assertEquals(1, set.getSources(key1).size());
assertTrue(set.getSources(key1).contains(source));
assertInSet(set, key1, 1, source);

set.add(key2, state2, source);
assertTrue(set.contains(key2));

// Same source so still only one value.
assertEquals(1, set.getSources(key2).size());
assertTrue(set.getSources(key1).contains(source));
assertInSet(set, key2, 1, source);

WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
Expand All @@ -322,11 +257,9 @@ public void testEviction_keyAndSourceOverlap_nonNull() {

awaitFullGc();

assertTrue(set.contains(key));

// Should still have a single source.
assertEquals(1, set.getSources(key).size());
assertTrue(set.getSources(key1).contains(source));
// Same source so still only one value.
assertInSet(set, key, 1, source);
assertInSet(set, key1, 1, source);

source = null;

Expand All @@ -339,8 +272,7 @@ public void testEviction_keyAndSourceOverlap_nonNull() {

awaitFullGc();

assertFalse(set.contains(key));
assertNull(set.getSources(key));
assertNotInSet(set, key);

awaitClear(weakKey2Ref);
awaitClear(weakSourceRef);
Expand All @@ -360,19 +292,13 @@ public void testEviction_keyOverlap_3x() {
Object source3 = new Object();

set.add(key1, state1, source1);
assertTrue(set.contains(key1));
assertEquals(1, set.getSources(key1).size());
assertTrue(set.getSources(key1).contains(source1));
assertInSet(set, key1, 1, source1);

set.add(key2, state2, source2);
assertTrue(set.contains(key2));
assertEquals(2, set.getSources(key2).size());
assertTrue(set.getSources(key1).containsAll(Arrays.asList(source1, source2)));
assertInSet(set, key1, 2, source1, source2);

set.add(key3, state3, source3);
assertTrue(set.contains(key3));
assertEquals(3, set.getSources(key3).size());
assertTrue(set.getSources(key1).containsAll(Arrays.asList(source1, source2, source3)));
assertInSet(set, key1, 3, source1, source2, source3);

WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
Expand All @@ -385,10 +311,8 @@ public void testEviction_keyOverlap_3x() {
state1 = null;

awaitFullGc();

assertTrue(set.contains(key));
assertEquals(2, set.getSources(key).size());
assertTrue(set.getSources(key).containsAll(Arrays.asList(source2, source3)));
assertSourceNotInSet(set, key, source1);
assertInSet(set, key, 2, source2, source3);

source1 = null;
// Key1 will be referenced as the key in the sources backingSet and won't be
Expand All @@ -397,10 +321,8 @@ public void testEviction_keyOverlap_3x() {

state2 = null;
awaitFullGc();

assertTrue(set.contains(key));
assertEquals(1, set.getSources(key).size());
assertTrue(set.getSources(key).contains(source3));
assertSourceNotInSet(set, key, source2);
assertInSet(set, key, 1, source3);

awaitClear(weakKey2Ref);

Expand All @@ -411,9 +333,7 @@ public void testEviction_keyOverlap_3x() {

state3 = null;
awaitFullGc();

assertFalse(set.contains(Key.get(Integer.class)));
assertNull(set.getSources(Key.get(Integer.class)));
assertNotInSet(set, key);

awaitClear(weakKey3Ref);
source3 = null;
Expand Down Expand Up @@ -518,19 +438,7 @@ public void testWeakKeySet_integration_multipleChildren_overlappingKeys() {
awaitClear(weakRef2);
assertNotBlacklisted(parentInjector, Key.get(String.class));
}

private static void assertBlacklisted(Injector injector, Key<?> key) {
assertBlacklistState(injector, key, true);
}

private static void assertNotBlacklisted(Injector injector, Key<?> key) {
assertBlacklistState(injector, key, false);
}

private static void assertBlacklistState(Injector injector, Key<?> key, boolean isBlacklisted) {
assertEquals(isBlacklisted, ((InjectorImpl) injector).state.isBlacklisted(key));
}

private static class TestState implements State {
public State parent() {
return new TestState();
Expand Down
Loading

0 comments on commit 0c27536

Please sign in to comment.