You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2005/07/05 05:44:08 UTC

svn commit: r209204 - in /jakarta/commons/sandbox/id/trunk/src: java/org/apache/commons/id/uuid/NodeManagerImpl.java test/org/apache/commons/id/uuid/NodeManagerImplTest.java

Author: psteitz
Date: Mon Jul  4 20:44:07 2005
New Revision: 209204

URL: http://svn.apache.org/viewcvs?rev=209204&view=rev
Log:
Fixed NodeManagerImpl index increment bug. BZ #35601. Reported by John Gregg.

Added:
    jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/NodeManagerImplTest.java   (with props)
Modified:
    jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java

Modified: jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java?rev=209204&r1=209203&r2=209204&view=diff
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java (original)
+++ jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java Mon Jul  4 20:44:07 2005
@@ -67,7 +67,7 @@
         allNodes = new Node[nodesSet.size()];
         int i = 0;
         while (it.hasNext()) {
-            allNodes[i] = (Node) it.next();
+            allNodes[i++] = (Node) it.next();
         }
         isInit = true;
     }

Added: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/NodeManagerImplTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/NodeManagerImplTest.java?rev=209204&view=auto
==============================================================================
--- jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/NodeManagerImplTest.java (added)
+++ jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/NodeManagerImplTest.java Mon Jul  4 20:44:07 2005
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.id.uuid;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.apache.commons.id.uuid.state.ReadOnlyResourceStateImpl;
+import org.apache.commons.id.uuid.state.Node;
+
+/**
+ * Unit tests for {@link NodeManagerImpl}.
+ *
+ * @version $Revision$ $Date$
+ * @author Commons-id team
+ */
+public class NodeManagerImplTest extends TestCase {
+
+    /** Pre test value for ReadOnlyResourceStateImpl.CONFIG_FILE_KEY */
+    private String currentConfigFile;
+    
+ 
+    public NodeManagerImplTest(String name) {
+        super(name);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(NodeManagerImplTest.class);
+        suite.setName("NodeManagerImpl Tests");
+        return suite;
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        currentConfigFile = System.getProperty(
+                ReadOnlyResourceStateImpl.CONFIG_FILENAME_KEY);
+    }
+
+    protected void tearDown() throws Exception {
+        if (currentConfigFile != null) {
+            System.setProperty(
+                    ReadOnlyResourceStateImpl.CONFIG_FILENAME_KEY,
+                    currentConfigFile);
+        }
+        super.tearDown();
+    }
+
+    public void testInit() throws Exception {
+        System.setProperty(ReadOnlyResourceStateImpl.CONFIG_FILENAME_KEY,
+                "uuid1.state");  // sets up 2 different nodes
+        NodeManagerImpl nodeManager = new NodeManagerImpl();
+        nodeManager.init();
+        Node node1 = nodeManager.currentNode();
+        assertNotNull(node1);
+        Node node2 = nodeManager.nextAvailableNode();
+        assertNotNull(node2);
+        assertFalse(node1.equals(node2));
+        node2 = nodeManager.nextAvailableNode();  // should wrap back to node 1
+        assertEquals(node1, node2);
+    }
+
+}

Propchange: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/NodeManagerImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/NodeManagerImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/NodeManagerImplTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org