You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/02/13 16:12:34 UTC

[14/18] syncope git commit: [SYNCOPE-641] Adding test class

[SYNCOPE-641] Adding test class


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

Branch: refs/heads/2_0_X
Commit: 223c0cda4ad43581860df1a892de1d2191222856
Parents: 0a1b3e9
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Fri Feb 13 16:11:09 2015 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Fri Feb 13 16:11:09 2015 +0100

----------------------------------------------------------------------
 .../apache/syncope/client/ConcurrencyTest.java  | 71 ++++++++++++++++++++
 1 file changed, 71 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/223c0cda/client/src/test/java/org/apache/syncope/client/ConcurrencyTest.java
----------------------------------------------------------------------
diff --git a/client/src/test/java/org/apache/syncope/client/ConcurrencyTest.java b/client/src/test/java/org/apache/syncope/client/ConcurrencyTest.java
new file mode 100644
index 0000000..c7228c3
--- /dev/null
+++ b/client/src/test/java/org/apache/syncope/client/ConcurrencyTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.syncope.client;
+
+import static org.junit.Assert.fail;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.common.services.ResourceService;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ConcurrencyTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ConcurrencyTest.class);
+
+    private static final SyncopeClient client =
+            new SyncopeClientFactoryBean().setAddress("http://url").create("username", "password");
+
+    @Test
+    public void multiThreadTest()
+            throws InterruptedException {
+
+        for (int i = 0; i < 10000; i++) {
+            Thread execution = new Thread("Th-" + StringUtils.leftPad(String.valueOf(i), 5, '0')) {
+
+                @Override
+                public void run() {
+
+                    try {
+                        client.getService(ResourceService.class);
+
+                        LOG.info(getName() + " completed successfully!");
+                    } catch (Exception e) {
+                        LOG.error(getName() + " did not complete", e);
+                    }
+                }
+            };
+            execution.start();
+        }
+
+        Thread.sleep(10000);
+    }
+
+    @Test
+    public void multiCallTest() {
+        try {
+            for (int i = 0; i < 10000; i++) {
+                client.getService(ResourceService.class);
+            }
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
+}