You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/05/10 21:11:01 UTC
[05/18] incubator-geode git commit: Moving a distributed lock service
unit test to open-source.
Moving a distributed lock service unit test to open-source.
There are still a few distributed unit tests that haven't been ported to
Geode. This one covers a lot of the functionality of the distributed lock
service.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/2c148caa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/2c148caa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/2c148caa
Branch: refs/heads/feature/GEODE-1369
Commit: 2c148caaf6a484bce065843d4d6ba8e916bd9ad2
Parents: 717ba5c
Author: Bruce Schuchardt <bs...@pivotal.io>
Authored: Mon May 9 15:08:31 2016 -0700
Committer: Bruce Schuchardt <bs...@pivotal.io>
Committed: Mon May 9 15:09:47 2016 -0700
----------------------------------------------------------------------
.../distributed/DistributedLockBlackboard.java | 20 +
.../DistributedLockBlackboardImpl.java | 97 +
.../DistributedLockServiceDUnitTest.java | 3246 ++++++++++++++++++
.../test/dunit/standalone/DUnitLauncher.java | 3 +-
4 files changed, 3365 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2c148caa/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
new file mode 100755
index 0000000..de8809c
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboard.java
@@ -0,0 +1,20 @@
+package com.gemstone.gemfire.distributed;
+
+import java.io.Serializable;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * Created by bschuchardt on 5/9/2016.
+ */
+public interface DistributedLockBlackboard extends Remote, Serializable {
+ void initCount() throws RemoteException;
+
+ void incCount() throws RemoteException;
+
+ long getCount() throws RemoteException;
+
+ void setIsLocked(boolean isLocked) throws RemoteException;
+
+ boolean getIsLocked() throws RemoteException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2c148caa/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboardImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboardImpl.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboardImpl.java
new file mode 100755
index 0000000..6525cd1
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedLockBlackboardImpl.java
@@ -0,0 +1,97 @@
+/*
+ * 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 com.gemstone.gemfire.distributed;
+
+import com.gemstone.gemfire.internal.Assert;
+import com.gemstone.gemfire.test.dunit.standalone.DUnitLauncher;
+
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+
+
+public class DistributedLockBlackboardImpl extends UnicastRemoteObject implements DistributedLockBlackboard {
+ public static int Count;
+ public static int IsLocked;
+
+ public static DistributedLockBlackboard blackboard;
+
+ /**
+ * Zero-arg constructor for remote method invocations.
+ */
+ public DistributedLockBlackboardImpl() throws RemoteException {
+ super();
+ }
+
+ /**
+ * Creates a singleton event listeners blackboard.
+ */
+ public static DistributedLockBlackboard getInstance() throws Exception {
+ if ( blackboard == null )
+ initialize();
+ return blackboard;
+ }
+ private static synchronized void initialize() throws Exception {
+ if ( blackboard == null ) {
+ System.out.println(DUnitLauncher.RMI_PORT_PARAM + "=" + System.getProperty(DUnitLauncher.RMI_PORT_PARAM));
+ int namingPort = Integer.getInteger(DUnitLauncher.RMI_PORT_PARAM).intValue();
+ String name = "//localhost:" + namingPort + "/" + "DistributedLockBlackboard";
+ try {
+ blackboard = (DistributedLockBlackboard)Naming.lookup(name);
+ } catch (NotBoundException e) {
+ // create the master blackboard in this VM
+ blackboard = new DistributedLockBlackboardImpl();
+ Naming.bind(name, blackboard);
+ }
+ }
+ }
+
+ @Override
+ public synchronized void initCount() {
+ Count = 0;
+ }
+
+ @Override
+ public synchronized void incCount() {
+ Count = Count + 1;
+ }
+
+
+ @Override
+ public synchronized long getCount() {
+ return Count;
+ }
+
+ @Override
+ public synchronized void setIsLocked(boolean isLocked) {
+ if (isLocked) {
+ if (IsLocked < 1) IsLocked = 1;
+ } else {
+ if (IsLocked > 0) IsLocked = 0;
+ }
+ }
+
+ @Override
+ public synchronized boolean getIsLocked() {
+ long isLocked = IsLocked;
+ Assert.assertTrue(isLocked == 0 || isLocked == 1,
+ "DistributedLockBlackboard internal error - IsLocked is " + isLocked);
+ return isLocked == 1;
+ }
+
+}