You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2016/05/01 12:56:44 UTC

[42/50] [abbrv] maven-aether git commit: Bug 449590 - DefaultRepositoryCache.put() with null data fails to update cache

Bug 449590 - DefaultRepositoryCache.put() with null data fails to update cache

Fixed DefaultRepositoryCache.put() to remove mapping if value is null


Project: http://git-wip-us.apache.org/repos/asf/maven-aether/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-aether/commit/396bc8c9
Tree: http://git-wip-us.apache.org/repos/asf/maven-aether/tree/396bc8c9
Diff: http://git-wip-us.apache.org/repos/asf/maven-aether/diff/396bc8c9

Branch: refs/heads/master
Commit: 396bc8c9668a55f2f5d03527ade61a55d0c511fe
Parents: ed23cf8
Author: Benjamin Bentmann <be...@sonatype.com>
Authored: Sat Nov 1 17:40:19 2014 +0100
Committer: Benjamin Bentmann <be...@sonatype.com>
Committed: Sat Nov 1 17:40:19 2014 +0100

----------------------------------------------------------------------
 .../eclipse/aether/DefaultRepositoryCache.java  |   6 +-
 .../aether/DefaultRepositoryCacheTest.java      | 103 +++++++++++++++++++
 2 files changed, 108 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-aether/blob/396bc8c9/aether-api/src/main/java/org/eclipse/aether/DefaultRepositoryCache.java
----------------------------------------------------------------------
diff --git a/aether-api/src/main/java/org/eclipse/aether/DefaultRepositoryCache.java b/aether-api/src/main/java/org/eclipse/aether/DefaultRepositoryCache.java
index 94664ea..12d2789 100644
--- a/aether-api/src/main/java/org/eclipse/aether/DefaultRepositoryCache.java
+++ b/aether-api/src/main/java/org/eclipse/aether/DefaultRepositoryCache.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 Sonatype, Inc.
+ * Copyright (c) 2010, 2014 Sonatype, Inc.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -34,6 +34,10 @@ public final class DefaultRepositoryCache
         {
             cache.put( key, data );
         }
+        else
+        {
+            cache.remove( key );
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/maven-aether/blob/396bc8c9/aether-api/src/test/java/org/eclipse/aether/DefaultRepositoryCacheTest.java
----------------------------------------------------------------------
diff --git a/aether-api/src/test/java/org/eclipse/aether/DefaultRepositoryCacheTest.java b/aether-api/src/test/java/org/eclipse/aether/DefaultRepositoryCacheTest.java
new file mode 100644
index 0000000..59dbd76
--- /dev/null
+++ b/aether-api/src/test/java/org/eclipse/aether/DefaultRepositoryCacheTest.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.aether;
+
+import static org.junit.Assert.*;
+
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.junit.Test;
+
+public class DefaultRepositoryCacheTest
+{
+
+    private DefaultRepositoryCache cache = new DefaultRepositoryCache();
+
+    private RepositorySystemSession session = new DefaultRepositorySystemSession();
+
+    private Object get( Object key )
+    {
+        return cache.get( session, key );
+    }
+
+    private void put( Object key, Object value )
+    {
+        cache.put( session, key, value );
+    }
+
+    @Test( expected = RuntimeException.class )
+    public void testGet_NullKey()
+    {
+        get( null );
+    }
+
+    @Test( expected = RuntimeException.class )
+    public void testPut_NullKey()
+    {
+        put( null, "data" );
+    }
+
+    @Test
+    public void testGetPut()
+    {
+        Object key = "key";
+        assertNull( get( key ) );
+        put( key, "value" );
+        assertEquals( "value", get( key ) );
+        put( key, "changed" );
+        assertEquals( "changed", get( key ) );
+        put( key, null );
+        assertNull( get( key ) );
+    }
+
+    @Test( timeout = 10000 )
+    public void testConcurrency()
+        throws Exception
+    {
+        final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
+        Thread threads[] = new Thread[20];
+        for ( int i = 0; i < threads.length; i++ )
+        {
+            threads[i] = new Thread()
+            {
+                @Override
+                public void run()
+                {
+                    for ( int i = 0; i < 100; i++ )
+                    {
+                        String key = UUID.randomUUID().toString();
+                        try
+                        {
+                            put( key, Boolean.TRUE );
+                            assertEquals( Boolean.TRUE, get( key ) );
+                        }
+                        catch ( Throwable t )
+                        {
+                            error.compareAndSet( null, t );
+                            t.printStackTrace();
+                        }
+                    }
+                }
+            };
+        }
+        for ( Thread thread : threads )
+        {
+            thread.start();
+        }
+        for ( Thread thread : threads )
+        {
+            thread.join();
+        }
+        assertNull( String.valueOf( error.get() ), error.get() );
+    }
+
+}