001
014
015 package com.liferay.portal.kernel.test.ci;
016
017 import com.liferay.portal.kernel.util.ArrayUtil;
018 import com.liferay.portal.kernel.util.CharPool;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.StringUtil;
021
022 import org.junit.BeforeClass;
023
024
027 public abstract class AutoBalanceTestCase {
028
029 @BeforeClass
030 public static void setUpClass() {
031 testClassGroupIndex = GetterUtil.getInteger(
032 System.getProperty("test.class.group.index"), -1);
033
034 if (testClassGroupIndex >= 0) {
035 String[] testClassGroupArray = StringUtil.split(
036 System.getProperty("test.class.groups"), CharPool.SPACE);
037
038 testClassGroupsSize = testClassGroupArray.length;
039 }
040
041 if (isCIMode()) {
042 System.out.println(
043 "Running in CI mode with " + (testClassGroupIndex + 1) +
044 "/" + testClassGroupsSize);
045 }
046 }
047
048 protected static boolean isCIMode() {
049 if ((testClassGroupIndex >= 0) && (testClassGroupsSize > 0)) {
050 return true;
051 }
052
053 return false;
054 }
055
056 protected static <T> T[] slice(T[] array) {
057 int groupSize = array.length / testClassGroupsSize;
058
059 if ((array.length % testClassGroupsSize) != 0) {
060 groupSize++;
061 }
062
063 int start = groupSize * testClassGroupIndex;
064 int end = start + groupSize;
065
066 if (end > array.length) {
067 end = array.length;
068 }
069
070 return ArrayUtil.subset(array, start, end);
071 }
072
073 protected static int testClassGroupIndex;
074 protected static int testClassGroupsSize;
075
076 }