usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [2/2] usergrid git commit: WIP Overwrite
Date Wed, 02 Sep 2015 20:59:00 GMT
WIP Overwrite


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/d75b91d2
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/d75b91d2
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/d75b91d2

Branch: refs/heads/USERGRID-909
Commit: d75b91d2e591dd04e62c92eaa567acdfe5f5ab11
Parents: aff3935
Author: Todd Nine <tnine@apigee.com>
Authored: Wed Sep 2 14:58:52 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Wed Sep 2 14:58:52 2015 -0600

----------------------------------------------------------------------
 .../persistence/graph/guice/GraphModule.java    |   5 +-
 stack/corepersistence/locks/pom.xml             |   8 ++
 .../persistence/locks/guice/LockModule.java     |   2 +-
 .../locks/impl/CassandraMultiRegionLock.java    |   6 +-
 .../persistence/locks/impl/LockCandidate.java   |   4 -
 .../NodeShardProposalSerializationTest.java     | 114 +++++++++++++++++++
 .../locks/impl/LockCandidateTest.java           |  50 ++++++++
 .../persistence/locks/impl/TestLockModule.java  |  38 +++++++
 8 files changed, 214 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/d75b91d2/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
index 1cca5b2..c7bfd37 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/guice/GraphModule.java
@@ -61,18 +61,16 @@ import org.apache.usergrid.persistence.graph.serialization.impl.shard.EdgeShardS
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.NodeShardAllocation;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.NodeShardApproximation;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.NodeShardCache;
-import org.apache.usergrid.persistence.graph.serialization.impl.shard.ShardConsistency;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.ShardGroupCompaction;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.ShardedEdgeSerialization;
+import org.apache.usergrid.persistence.graph.serialization.impl.shard.ShardedEdgeSerializationImpl;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.count.NodeShardApproximationImpl;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.count.NodeShardCounterSerialization;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.count.NodeShardCounterSerializationImpl;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.impl.EdgeShardSerializationImpl;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.impl.NodeShardAllocationImpl;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.impl.NodeShardCacheImpl;
-import org.apache.usergrid.persistence.graph.serialization.impl.shard.impl.ShardConsistencyImpl;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.impl.ShardGroupCompactionImpl;
-import org.apache.usergrid.persistence.graph.serialization.impl.shard.ShardedEdgeSerializationImpl;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.impl.SizebasedEdgeColumnFamilies;
 import org.apache.usergrid.persistence.graph.serialization.impl.shard.impl.SizebasedEdgeShardStrategy;
 
@@ -116,7 +114,6 @@ public abstract class GraphModule extends AbstractModule {
         bind( NodeShardApproximation.class ).to( NodeShardApproximationImpl.class );
         bind( NodeShardCache.class ).to( NodeShardCacheImpl.class );
         bind( NodeShardCounterSerialization.class ).to( NodeShardCounterSerializationImpl.class
);
-        bind( ShardConsistency.class).to( ShardConsistencyImpl.class);
 
 
         /**

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d75b91d2/stack/corepersistence/locks/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/pom.xml b/stack/corepersistence/locks/pom.xml
index 8747658..de89053 100644
--- a/stack/corepersistence/locks/pom.xml
+++ b/stack/corepersistence/locks/pom.xml
@@ -50,6 +50,14 @@
             <scope>test</scope>
         </dependency>
 
+
+        <dependency>
+          <groupId>org.mockito</groupId>
+          <artifactId>mockito-core</artifactId>
+          <version>${mockito.version}</version>
+          <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d75b91d2/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/guice/LockModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/guice/LockModule.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/guice/LockModule.java
index 4b0d433..d1e066c 100644
--- a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/guice/LockModule.java
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/guice/LockModule.java
@@ -32,7 +32,7 @@ import com.google.inject.AbstractModule;
 /**
  * Guice configuration of the lock module
  */
-public abstract class LockModule extends AbstractModule {
+public class LockModule extends AbstractModule {
 
     @Override
     protected void configure() {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d75b91d2/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraMultiRegionLock.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraMultiRegionLock.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraMultiRegionLock.java
index e3d6362..62c157e 100644
--- a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraMultiRegionLock.java
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/CassandraMultiRegionLock.java
@@ -53,11 +53,9 @@ public class CassandraMultiRegionLock implements Lock {
 
         Preconditions.checkArgument(expiration > Integer.MAX_VALUE, "Expiration cannot
be longer than "  + Integer.MAX_VALUE);
 
-        this.nodeShardProposalSerialization.writeNewValue( lockId, lockUUID, ( int ) expiration
);
+        final LockCandidate lockCandidate = this.nodeShardProposalSerialization.writeNewValue(
lockId, lockUUID, ( int ) expiration );
 
-        //now read back our proposal
-
-        final LockCandidate lockCandidate = nodeShardProposalSerialization.getProposedLock(
lockId );
+        //now check if we need to ack our previous
 
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d75b91d2/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/LockCandidate.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/LockCandidate.java
b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/LockCandidate.java
index ed25b38..cd0722c 100644
--- a/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/LockCandidate.java
+++ b/stack/corepersistence/locks/src/main/java/org/apache/usergrid/persistence/locks/impl/LockCandidate.java
@@ -93,8 +93,4 @@ public class LockCandidate {
 
     }
 
-
-    public UUID getFirst() {
-        return first;
-    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d75b91d2/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/guice/NodeShardProposalSerializationTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/guice/NodeShardProposalSerializationTest.java
b/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/guice/NodeShardProposalSerializationTest.java
new file mode 100644
index 0000000..67b27e8
--- /dev/null
+++ b/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/guice/NodeShardProposalSerializationTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.usergrid.persistence.locks.guice;
+
+
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.core.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.core.test.ITRunner;
+import org.apache.usergrid.persistence.core.test.UseModules;
+import org.apache.usergrid.persistence.locks.LockId;
+import org.apache.usergrid.persistence.locks.impl.LockCandidate;
+import org.apache.usergrid.persistence.locks.impl.NodeShardProposalSerialization;
+import org.apache.usergrid.persistence.locks.impl.TestLockModule;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.inject.Inject;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+
+@RunWith(ITRunner.class)
+@UseModules({ TestLockModule.class })
+public class NodeShardProposalSerializationTest {
+
+    private static final Logger log = LoggerFactory.getLogger( NodeShardProposalSerializationTest.class
);
+
+    @Inject
+    @Rule
+    public MigrationManagerRule migrationManagerRule;
+
+
+    @Inject
+    protected NodeShardProposalSerialization serialization;
+
+
+    protected ApplicationScope scope;
+
+    protected final AtomicLong atomicLong = new AtomicLong(  );
+
+
+    private static final int ONE_HOUR_TTL = 360;
+
+    @Before
+    public void setup() {
+        scope = mock( ApplicationScope.class );
+
+        Id orgId = mock( Id.class );
+
+        when( orgId.getType() ).thenReturn( "organization" );
+        when( orgId.getUuid() ).thenReturn( UUIDGenerator.newTimeUUID() );
+
+        when( scope.getApplication() ).thenReturn( orgId );
+
+
+
+
+    }
+
+    @Test
+    public void testOnlyLock(){
+
+        final LockId testId = createLockId();
+        final UUID proposed = UUIDGenerator.newTimeUUID();
+
+
+
+        final LockCandidate candidate =  serialization.writeNewValue( testId, proposed, ONE_HOUR_TTL
);
+
+
+        assertNotNull(candidate);
+
+        assertTrue(proposed, candidate.isFirst(proposed));
+    }
+
+    private LockId createLockId(){
+
+        LockId lockId = mock(LockId.class);
+                 //mock up scope
+                 when( lockId.getApplicationScope()).thenReturn( scope );
+
+                 when( lockId.generateKey()).thenReturn( atomicLong.incrementAndGet() + ""
);
+
+        return lockId;
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d75b91d2/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/impl/LockCandidateTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/impl/LockCandidateTest.java
b/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/impl/LockCandidateTest.java
new file mode 100644
index 0000000..2d9ddd5
--- /dev/null
+++ b/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/impl/LockCandidateTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.usergrid.persistence.locks.impl;
+
+
+import java.util.UUID;
+
+import org.junit.Test;
+
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.common.base.Optional;
+
+import static org.junit.Assert.*;
+
+
+public class LockCandidateTest {
+
+    @Test
+    public void testOnlyUUID(){
+        final UUID proposedUuid = UUIDGenerator.newTimeUUID();
+
+        final LockCandidate candidate = new LockCandidate( proposedUuid, Optional.absent(),
Optional.absent() );
+
+        assertTrue( "UUID should be first", candidate.isFirst( proposedUuid ) );
+
+        final UUID otherUuid = UUIDGenerator.newTimeUUID();
+
+        assertFalse("UUID is not first", candidate.isFirst( otherUuid ));
+
+        assertTrue( "Should have lock", candidate.isLocked( proposedUuid ) );
+
+        assertFalse("Should not have lock", candidate.isLocked( otherUuid ));
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d75b91d2/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/impl/TestLockModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/impl/TestLockModule.java
b/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/impl/TestLockModule.java
new file mode 100644
index 0000000..3caf3f8
--- /dev/null
+++ b/stack/corepersistence/locks/src/test/java/org/apache/usergrid/persistence/locks/impl/TestLockModule.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.usergrid.persistence.locks.impl;
+
+
+import org.apache.usergrid.persistence.core.guice.CommonModule;
+import org.apache.usergrid.persistence.core.guice.TestModule;
+import org.apache.usergrid.persistence.locks.guice.LockModule;
+
+
+/**
+ * Wrapper for configuring our guice test env
+ */
+public class TestLockModule extends TestModule {
+
+    @Override
+    protected void configure() {
+        /**
+         * Runtime modules
+         */
+        install( new CommonModule() );
+        install( new LockModule() );
+    }
+}


Mime
View raw message