Author: shawkins
Date: 2009-05-07 17:35:26 -0400 (Thu, 07 May 2009)
New Revision: 885
Added:
trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java
trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java
Removed:
trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java
trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java
trunk/common-internal/src/main/java/com/metamatrix/common/util/Intervals.java
trunk/common-internal/src/main/java/com/metamatrix/common/util/MultipleRequestConfirmation.java
trunk/common-internal/src/test/java/com/metamatrix/common/util/TestIntervals.java
trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CursorReceiverWindowBuffer.java
trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestCursorReceiverWindowBuffer.java
Modified:
trunk/common-core/src/main/java/com/metamatrix/core/util/NamedThreadFactory.java
trunk/common-core/src/main/java/com/metamatrix/core/util/StringUtil.java
trunk/common-core/src/test/java/com/metamatrix/core/util/TestStringUtil.java
trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CacheResults.java
trunk/engine/src/main/java/org/teiid/dqp/internal/cache/ResultSetCache.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItemFactory.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestResultSetCache.java
trunk/soap/src/main/java/com/metamatrix/soap/handler/ActionUpdateHandler.java
trunk/soap/src/main/java/com/metamatrix/soap/service/DataServiceWebServiceImpl.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java
trunk/soap/src/main/java/com/metamatrix/soap/servlet/WSDLURLGenerator.java
trunk/soap/src/main/java/com/metamatrix/soap/util/EndpointUriTranslatorStrategyImpl.java
trunk/soap/src/test/java/com/metamatrix/soap/handler/TestActionUpdateHandler.java
trunk/soap/src/test/java/com/metamatrix/soap/service/TestDataServiceWebServiceImpl.java
trunk/soap/src/test/java/com/metamatrix/soap/servlet/TestMMGetVDBResourceServlet.java
Log:
Moving WSDLServletUtil out of common core, simplifying rs cache logic
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java
===================================================================
---
trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -1,225 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Constants pertaining to WSDL servlet execution.
- *
- * @since 4.2
- */
-
-public class WSDLServletUtil {
-
- /**
- * General keys
- */
- public static final String SERVER_URL_KEY = "ServerURL"; //$NON-NLS-1$
-
- public static final String SECURE_PROTOCOL = "Secure"; //$NON-NLS-1$
-
- public static final String VDB_NAME_KEY = "VDBName"; //$NON-NLS-1$
-
- public static final String VDB_VERSION_KEY = "VDBVersion"; //$NON-NLS-1$
-
- public static final String ADD_PROPS = "AdditionalProperties"; //$NON-NLS-1$
-
- public static final String TXN_AUTO_WRAP = "txnAutoWrap"; //$NON-NLS-1$
-
- public static final String ADD_EXEC_PROPS = "AddExecProperties";
//$NON-NLS-1$
-
- public static final String MM_WEBSERVICE_QUERY_TIMEOUT =
"com.metamatrix.webservice.querytimeout"; //$NON-NLS-1$
-
- public static final String DISCOVERED_WSDL = "discovered_wsdl"; //$NON-NLS-1$
-
- /*
- * This is the parameter that will tell this servlet when the web service endpoint as
defined in WSDL served up by this
- * servlet will use the HTTP vs HTTPS protocol.
- */
- public static final String HTTP_TYPE_PARAMETER_KEY = "httptype";
//$NON-NLS-1$
-
- /*
- * This is the value of the httptype URL request param that will indicate that the
returned WSDL should have an http endpoint
- * instead of an https endpoint.
- */
- public static final String HTTP_PARAMETER_VALUE = "http"; //$NON-NLS-1$
-
- /*
- * Static contant representing the standard http protocol.
- */
- public static final String HTTP = "http"; //$NON-NLS-1$
-
- /**
- * Static contant representing the secure http protocol.
- */
- public static final String HTTPS = "https"; //$NON-NLS-1$
-
- /**
- * Default content type for the VDBResourceServlet
- */
- public static final String DEFAULT_CONTENT_TYPE = "text/html"; //$NON-NLS-1$
-
- /**
- * XML content type for the VDBResourceServlet
- */
- public static final String XML_CONTENT_TYPE = "text/xml"; //$NON-NLS-1$
-
- /**
- * WSDL URL Generator keys
- */
- public static final String MMSERVER_HOST_PORT_KEY = "MMServerHostAndPort";
//$NON-NLS-1$
-
- public static final String TARGET_HOST_KEY = "TargetHost"; //$NON-NLS-1$
-
- public static final String TARGET_PORT_KEY = "TargetPort"; //$NON-NLS-1$
-
- public static final String SERVLET_PATH = "/servlet/ArtifactDocumentService";
//$NON-NLS-1$
-
- public static final String SQLQUERYWEBSERVICE_WSDL_PATH =
"/services/SqlQueryWebService?wsdl"; //$NON-NLS-1$
-
- public static final String GENERATED_WSDL_NAME = "MetaMatrixDataServices";
//$NON-NLS-1$
-
- public static final String GENERATED_WSDL_FILENAME = GENERATED_WSDL_NAME +
".wsdl"; //$NON-NLS-1$
-
- public static final String COLON = ":"; //$NON-NLS-1$
-
- public static final String SLASH = "/"; //$NON-NLS-1$
-
- public static final String DOUBLE_SLASH = "//"; //$NON-NLS-1$
-
- public static final String AMP = "&"; //$NON-NLS-1$
-
- public static final String QUESTION_MARK = "?"; //$NON-NLS-1$
-
- public static final String EQUALS = "="; //$NON-NLS-1$
-
- public static final String COMMA = ","; //$NON-NLS-1$
-
- private static final String SQLQUERYWEBSERVICE_URL_FORMAT =
"{0}://{1}:{2}/{3}"; //$NON-NLS-1$
-
- /*
- * this default value is based on Tomcat's default value in its server.xml file.
This value can be overridden by setting the
- * com.metamatrix.webservice.dataservice.httpsport System property for the VM that this
servlet is running in.
- */
- private static final String DEFAULT_HTTPS_PORT = "8443"; //$NON-NLS-1$
-
- private static final String DEFAULT_HTTP_PORT = "8080"; //$NON-NLS-1$
-
- private static final String HTTPS_PORT_PROPERTY_KEY =
"com.metamatrix.webservice.dataservice.httpsport"; //$NON-NLS-1$
-
- private static final String HTTP_PORT_PROPERTY_KEY =
"com.metamatrix.webservice.dataservice.httpport"; //$NON-NLS-1$
-
- /**
- * Returns the formatted url from the supplied info
- *
- * @param scheme the server scheme
- * @param host the server host name
- * @param port the server port
- * @param appContext the context of this application to use in the WSDL url
- * @param serverURLs the list of server url info, first url is full url including
protocol. Subsequent items are just the
- * host:port strings.
- * @param vdbName the vdb name
- * @param vdbVersion the vdb version number
- */
- public static String formatURL( String scheme,
- String host,
- String port,
- String appContext,
- List serverURLs,
- String vdbName,
- String vdbVersion ) {
-
- StringBuffer result = new StringBuffer();
- try {
- boolean hasPort = true;
- boolean hasVDBVersion = true;
-
- if (port == null || port.length() == 0) {
- hasPort = false;
- }
-
- if (vdbVersion == null || vdbVersion.trim().length() == 0) {
- hasVDBVersion = false;
- }
-
- result.append(scheme).append(COLON).append(DOUBLE_SLASH).append(host);
-
- if (hasPort) {
- result.append(COLON).append(port);
- }
-
- result.append(appContext).append(SERVLET_PATH).append(SLASH).append(GENERATED_WSDL_FILENAME);
- result.append(QUESTION_MARK).append(SERVER_URL_KEY).append(EQUALS);
- // Append comma-delimited server urls
- Iterator iter = serverURLs.iterator();
- while (iter.hasNext()) {
- String serverURL = (String)iter.next();
- result.append(serverURL);
- // If there is another url coming, add an encoded comma
- if (iter.hasNext()) {
- result.append(URLEncoder.encode(COMMA, "UTF-8")); //$NON-NLS-1$
- }
- }
- result.append(AMP).append(VDB_NAME_KEY).append(EQUALS).append(vdbName);
- if (hasVDBVersion) {
- result.append(AMP).append(VDB_VERSION_KEY).append(EQUALS).append(vdbVersion);
- }
-
- } catch (UnsupportedEncodingException err) {
- // ignore
- }
-
- return result.toString();
- }
-
- /**
- * Returns the formatted wsdl url for the SqlQueryWebService
- *
- * @param server - server name
- * @param appContext the context of this application to use in the WSDL url
- * @param secure - secure ssl (true) or non-secure (false)
- * @return wsdlUrl - String
- * @since 4.3
- */
- public static String getSqlQueryWebServiceUrl( final String server,
- String appContext,
- final boolean secure ) {
-
- appContext=appContext.replace("/",""); //$NON-NLS-1$ //$NON-NLS-2$
- return MessageFormat.format(SQLQUERYWEBSERVICE_URL_FORMAT, new Object[] {secure ? HTTPS
: HTTP, server,
- secure ? getHttpsPort() : getHttpPort(),
appContext+SQLQUERYWEBSERVICE_WSDL_PATH});
- }
-
- public static final String getHttpsPort() {
- return System.getProperty(HTTPS_PORT_PROPERTY_KEY, DEFAULT_HTTPS_PORT);
- }
-
- public static final String getHttpPort() {
- return System.getProperty(HTTP_PORT_PROPERTY_KEY, DEFAULT_HTTP_PORT);
- }
-}
Modified:
trunk/common-core/src/main/java/com/metamatrix/core/util/NamedThreadFactory.java
===================================================================
---
trunk/common-core/src/main/java/com/metamatrix/core/util/NamedThreadFactory.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/common-core/src/main/java/com/metamatrix/core/util/NamedThreadFactory.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -1,3 +1,25 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
package com.metamatrix.core.util;
import java.util.concurrent.ThreadFactory;
Modified: trunk/common-core/src/main/java/com/metamatrix/core/util/StringUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/StringUtil.java 2009-05-07
21:28:59 UTC (rev 884)
+++ trunk/common-core/src/main/java/com/metamatrix/core/util/StringUtil.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -984,7 +984,7 @@
* @return
*/
@SuppressWarnings("unchecked")
- public static <T> T valueOf(String value, Class<T> type){
+ public static <T> T valueOf(String value, Class type){
if(type == String.class) {
return (T) value;
@@ -1013,6 +1013,10 @@
else if (type == Void.class) {
return null;
}
+ else if (type.isEnum()) {
+ return (T)Enum.valueOf(type, value);
+ }
+
else if (type.isAssignableFrom(Map.class)) {
List<String> l = Arrays.asList(value.split(",")); //$NON-NLS-1$
Map m = new HashMap<String, String>();
Deleted:
trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java
===================================================================
---
trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -1,106 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-/**
- */
-public class TestWSDLServletUtil extends TestCase {
-
- public static String HTTP = "http"; //$NON-NLS-1$
- public static String HTTPS = "https"; //$NON-NLS-1$
- public static String DEFAULT_APP_CONTEXT = "/metamatrix-soap"; //$NON-NLS-1$
- public static String OTHER_APP_CONTEXT = "/metamatrix-soapiness";
//$NON-NLS-1$
-
- public TestWSDLServletUtil(String name) {
- super(name);
- }
-
- public void testGetMMSAPIUrlAllNullServerNameSecure() {
- String url = WSDLServletUtil.getSqlQueryWebServiceUrl(null, DEFAULT_APP_CONTEXT,
true);
-
assertEquals("https://null:8443/metamatrix-soap/services/SqlQueryWebService?wsdl",
url); //$NON-NLS-1$
- }
-
- public void testGetMMSAPIUrlAllNullServerNameNonSecure() {
- String url = WSDLServletUtil.getSqlQueryWebServiceUrl(null, DEFAULT_APP_CONTEXT,
false);
-
assertEquals("http://null:8080/metamatrix-soap/services/SqlQueryWebService?wsdl",
url); //$NON-NLS-1$
- }
-
- public void testGetMMSAPIUrlValidParametersSecure() {
- String url = WSDLServletUtil.getSqlQueryWebServiceUrl("slntmm01",
DEFAULT_APP_CONTEXT, true); //$NON-NLS-1$
-
assertEquals("https://slntmm01:8443/metamatrix-soap/services/SqlQueryWebService?wsdl",
url); //$NON-NLS-1$
- }
-
- public void testGetMMSAPIUrlValidParametersNonSecure() {
- String url = WSDLServletUtil.getSqlQueryWebServiceUrl("slntmm01",
OTHER_APP_CONTEXT,false); //$NON-NLS-1$
-
assertEquals("http://slntmm01:8080/metamatrix-soapiness/services/SqlQueryWebService?wsdl",
url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersNonSecure() {
- List serverURLs = new ArrayList();
- serverURLs.add("mm://chicago:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTP,"chicago","8080",
DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-
assertEquals("http://chicago:8080/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mm://chicago:31000&VDBName=testVDB&VDBVersion=1",
url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersSecure() {
- List serverURLs = new ArrayList();
- serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
- String url =
WSDLServletUtil.formatURL(HTTPS,"chicago","8443", DEFAULT_APP_CONTEXT,
serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
-
assertEquals("https://chicago:8443/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mms://chicago:31000&VDBName=testVDB&VDBVersion=1",
url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersSecureNoPort() {
- List serverURLs = new ArrayList();
- serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTPS,"chicago",null,
DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
-
assertEquals("https://chicago/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mms://chicago:31000&VDBName=testVDB&VDBVersion=1",
url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersSecureNoPortNoVdbVersion() {
- List serverURLs = new ArrayList();
- serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTPS,"chicago",null,
OTHER_APP_CONTEXT, serverURLs,"testVDB",null); //$NON-NLS-1$ //$NON-NLS-2$
-
assertEquals("https://chicago/metamatrix-soapiness/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mms://chicago:31000&VDBName=testVDB",
url); //$NON-NLS-1$
- }
-
- public void testFormatUrlValidParametersSecureNoVdbVersion() {
- List serverURLs = new ArrayList();
- serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
- String url =
WSDLServletUtil.formatURL(HTTPS,"chicago","8443", DEFAULT_APP_CONTEXT,
serverURLs,"testVDB",""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
-
assertEquals("https://chicago:8443/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mms://chicago:31000&VDBName=testVDB",
url); //$NON-NLS-1$
- }
-
- public void testFormatUrlMultipleServers() {
- List serverURLs = new ArrayList();
- serverURLs.add("mm://chicago:31000"); //$NON-NLS-1$
- serverURLs.add("boston:31000"); //$NON-NLS-1$
- String url = WSDLServletUtil.formatURL(HTTP,"chicago","8080",
DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-
assertEquals("http://chicago:8080/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mm://chicago:31000%2Cboston:31000&VDBName=testVDB&VDBVersion=1",
url); //$NON-NLS-1$
- }
-
-}
Modified: trunk/common-core/src/test/java/com/metamatrix/core/util/TestStringUtil.java
===================================================================
---
trunk/common-core/src/test/java/com/metamatrix/core/util/TestStringUtil.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/common-core/src/test/java/com/metamatrix/core/util/TestStringUtil.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -387,6 +387,11 @@
assertEquals("vdb", StringUtil.getLastToken("/foo/bar.vdb",
"."));//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
+ public enum Test {
+ HELLO,
+ WORLD
+ }
+
public void testValueOf() {
assertEquals(Integer.valueOf(21), StringUtil.valueOf("21",
Integer.class)); //$NON-NLS-1$
assertEquals(Boolean.valueOf(true), StringUtil.valueOf("true",
Boolean.class)); //$NON-NLS-1$
@@ -405,6 +410,6 @@
assertEquals(3, m.size());
assertEquals(m.get("foo"), "bar"); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(m.get("x"), ""); //$NON-NLS-1$ //$NON-NLS-2$
-
+ assertEquals(Test.HELLO, StringUtil.valueOf("HELLO", Test.class));
//$NON-NLS-1$
}
}
Deleted: trunk/common-internal/src/main/java/com/metamatrix/common/util/Intervals.java
===================================================================
---
trunk/common-internal/src/main/java/com/metamatrix/common/util/Intervals.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/common-internal/src/main/java/com/metamatrix/common/util/Intervals.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -1,548 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.io.Serializable;
-import java.util.*;
-
-import com.metamatrix.common.CommonPlugin;
-
-/**
- * <p>This class can be used to represent a collection of intervals. As new
intervals are
- * added, they are merged into existing intervals to maintain the most compact
description
- * of the intervals that is possible. Interval endpoints are inclusive - a single index
- * can be identified by an interval like [1,1].</p.
- *
- * <p>For instance, if you added the intervals 1-3, 5-9, 4-4, they would be stored
as 1-9.</p>
- */
-public class Intervals implements Serializable {
-
- static int BEFORE_FIRST = 0;
- static int WITHIN_INTERVAL = 1;
- static int BETWEEN_INTERVALS = 2;
- static int AFTER_LAST = 3;
-
- private LinkedList intervals;
-
- /**
- * Constructor for Intervals.
- */
- public Intervals() {
- intervals = new LinkedList();
- }
-
- public Intervals(int begin, int end) {
- this();
- addInterval(begin, end);
- }
-
- /**
- * Copy constructor
- * @param intervals
- * @since 4.2
- */
- private Intervals(Collection i) {
- this.intervals = new LinkedList(i);
- }
-
- /**
- * True if this set of intervals contains any intervals.
- * @return True if covers anything, false otherwise
- */
- public boolean hasIntervals() {
- return (intervals.size() > 0);
- }
-
- /**
- * Add an interval from begin to end, inclusive.
- * @param begin Begin index
- * @param end End index
- * @throws IllegalArgumentException If begin > end
- */
- public void addInterval(int begin, int end) {
- if(begin > end) {
- throw new
IllegalArgumentException(CommonPlugin.Util.getString(ErrorMessageKeys.CM_UTIL_ERR_0023));
- }
-
- if(intervals.size() == 0) {
- // Add first interval
- intervals.add(new Integer(begin));
- intervals.add(new Integer(end));
-
- } else {
- int[] locations = findLocations(intervals, begin, end);
-
- if(locations[0] == BEFORE_FIRST) {
- if(locations[2] == BEFORE_FIRST) {
- intervals.addFirst(new Integer(end));
- intervals.addFirst(new Integer(begin));
- condense(intervals);
- return;
- } else if(locations[2] == AFTER_LAST) {
- intervals.clear();
- intervals.add(new Integer(begin));
- intervals.add(new Integer(end));
- return;
- }
- } else if(locations[0] == AFTER_LAST) {
- intervals.addLast(new Integer(begin));
- intervals.addLast(new Integer(end));
- condense(intervals);
- return;
-
- } else if(locations[0] == BETWEEN_INTERVALS && locations[2] ==
BETWEEN_INTERVALS && locations[1] > locations[3]) {
- // Insert between intervals
- intervals.add(locations[1], new Integer(end));
- intervals.add(locations[1], new Integer(begin));
- condense(intervals);
- return;
- }
-
- // All other cases:
-
- // Merge affected intervals
- mergeIntervals(intervals, locations[1], locations[3]);
-
- // Expand to handle added interval
- expandInterval(intervals, locations[1], begin, end);
-
- // Merge adjacent intervals
- condense(intervals);
- }
- }
-
- /**
- * Determines the type of location and relevant interval index for the specified
values. These
- * are returned stuffed into an int[] (yes this is ugly).
- * @param intervals Intervals to examine
- * @param beginValue Begin value we're trying to place within the intervals
- * @param endValue End value we're trying to place within the intervals
- * @return Four ints, first is begin location type as defined in javadoc, second is
begin index into intervals,
- * third is end location type as defined in javadoc, fourth is end index into
intervals
- */
- static int[] findLocations(LinkedList intervals, int beginValue, int endValue) {
- // Initialize return structure
- int[] locations = new int[4];
- locations[0] = -1;
- locations[2] = -1;
-
- int interval = -1;
- Iterator iter = intervals.iterator();
- while(iter.hasNext()) {
- // Update state
- int intervalBegin = ((Integer)iter.next()).intValue();
- int intervalEnd = ((Integer)iter.next()).intValue();
- interval++;
-
- // Determine if beginValue is before or within current interval
- if(locations[0] == -1) {
- if(beginValue < intervalBegin) {
- locations[0] = BETWEEN_INTERVALS;
- locations[1] = interval*2; // record this interval begin
- } else if(beginValue >= intervalBegin && beginValue <=
intervalEnd) {
- locations[0] = WITHIN_INTERVAL;
- locations[1] = interval*2; // record this interval begin
- }
- }
-
- // Determine if endValue is before or within current interval
- if(endValue < intervalBegin) {
- locations[2] = BETWEEN_INTERVALS;
- locations[3] = ((interval-1)*2)+1; // record previous interval end
- break;
- } else if(endValue >= intervalBegin && endValue <= intervalEnd)
{
- locations[2] = WITHIN_INTERVAL;
- locations[3] = (interval*2)+1; // record this interval end
- break;
- }
- }
-
- // Check for hanging conditions
- if(locations[2] == -1) {
- locations[2] = AFTER_LAST;
- locations[3] = intervals.size() - 1;
-
- if(locations[0] == -1) {
- locations[0] = AFTER_LAST;
- locations[1] = intervals.size() - 2;
- }
- }
-
- // Check for special case beginning conditions
- if(locations[0] == BETWEEN_INTERVALS && locations[1] == 0) {
- locations[0] = BEFORE_FIRST;
- }
-
- if(locations[2] == BETWEEN_INTERVALS && locations[3] < 0) {
- locations[2] = BEFORE_FIRST;
- }
-
- return locations;
- }
-
- static void mergeIntervals(LinkedList intervals, int firstIntervalIndex, int
lastIntervalIndex) {
- intervals.subList(firstIntervalIndex+1, lastIntervalIndex).clear();
- }
-
- static void expandInterval(LinkedList intervals, int firstIntervalIndex, int begin,
int end) {
- // Set up iterator
- ListIterator iter = intervals.listIterator(firstIntervalIndex);
-
- // Get merged interval bounds
- int mergedBegin = ((Integer) iter.next()).intValue();
- int mergedEnd = ((Integer) iter.next()).intValue();
-
- int newBegin = Math.min(begin, mergedBegin);
- int newEnd = Math.max(end, mergedEnd);
-
- // Change begin and end
- iter.previous();
- iter.set(new Integer(newEnd));
- iter.previous();
- iter.set(new Integer(newBegin));
- }
-
- static void reduceInterval(LinkedList intervals, int firstIntervalIndex, int begin,
int end) {
- // Set up iterator
- ListIterator iter = intervals.listIterator(firstIntervalIndex);
-
- // Get merged interval bounds
- int mergedBegin = ((Integer) iter.next()).intValue();
- int mergedEnd = ((Integer) iter.next()).intValue();
-
- if(begin <= mergedBegin) {
- if(end >= mergedEnd) {
- // Removed interval completely covers merged interval
- iter.previous();
- iter.remove();
- iter.previous();
- iter.remove();
- return;
- }
- // There is some left over at the right end of merged interval
- iter.previous();
- iter.previous();
- iter.set(new Integer(end+1));
- } else {
- if(end >= mergedEnd) {
- // There is some left over at the left end of merged interval
- iter.previous();
- iter.set(new Integer(begin-1));
-
- } else {
- // Removed interval is completely within merged interval - split in two
- iter.previous();
- iter.add(new Integer(end+1));
- iter.previous();
- iter.add(new Integer(begin-1));
- }
- }
- }
-
- static void condense(LinkedList intervals) {
- if(intervals.size() <= 2) {
- return;
- }
-
- ListIterator iter = intervals.listIterator();
-
- // Read first interval
- iter.next();
- int lastEnd = ((Integer) iter.next()).intValue();
-
- while(iter.hasNext()) {
- int begin = ((Integer) iter.next()).intValue();
- if(begin == lastEnd + 1) {
- iter.remove();
- iter.previous();
- iter.remove();
- }
- lastEnd = ((Integer) iter.next()).intValue();
- }
- }
-
- /**
- * Remove an interval from begin to end, inclusive. If the
- * current intervals do not contain anything in removed interval,
- * no error is thrown.
- * @param begin Begin index
- * @param end End index
- * @throws IllegalArgumentException If begin > end
- */
- public void removeInterval(int begin, int end) {
- if(begin > end) {
- throw new
IllegalArgumentException(CommonPlugin.Util.getString(ErrorMessageKeys.CM_UTIL_ERR_0024));
- }
-
- // Check whether we have any intervals
- if(intervals.size() == 0) {
- return;
- }
-
- // Check the locations of begin and end across locations
- int[] locations = findLocations(intervals, begin, end);
-
- if(locations[0] == BEFORE_FIRST) {
- if(locations[2] == BEFORE_FIRST) {
- return;
- } else if(locations[2] == AFTER_LAST) {
- intervals.clear();
- return;
- }
- } else if(locations[0] == AFTER_LAST) {
- return;
-
- } else if(locations[0] == BETWEEN_INTERVALS && locations[2] ==
BETWEEN_INTERVALS && locations[1] > locations[3]) {
- // Between intervals
- return;
- }
-
- // All other cases:
-
- // Merge affected intervals
- mergeIntervals(intervals, locations[1], locations[3]);
-
- // Expand to handle added interval
- reduceInterval(intervals, locations[1], begin, end);
-
- // Merge adjacent intervals
- condense(intervals);
- }
-
- public Intervals removeIntervals(Intervals intervalsToRemove) {
- List intervalList = intervalsToRemove.getIntervals();
- for (Iterator iterator = intervalList.iterator(); iterator.hasNext(); ) {
- int[] interval = (int[]) iterator.next();
- removeInterval(interval[0], interval[1]);
- }
- return this;
- }
-
- /**
- * Returns true if the specified interval is contained in the
- * current intervals.
- * @param begin Begin index
- * @param end End index
- * @throws IllegalArgumentException If begin > end
- */
- public boolean containsInterval(int begin, int end) {
- if(begin > end) {
- throw new
IllegalArgumentException(CommonPlugin.Util.getString(ErrorMessageKeys.CM_UTIL_ERR_0025));
- }
-
- // Check whether we have any intervals
- int size = intervals.size();
- if(size == 0) {
- return false;
- } else if (size == 2) {
- return (begin >= ((Integer) intervals.getFirst()).intValue() &&
end <= ((Integer) intervals.getLast()).intValue());
- }
-
- // Check whether the interval is contained completely within an existing
interval
- int[] locations = findLocations(intervals, begin, end);
- if(locations[0] == WITHIN_INTERVAL && locations[2] == WITHIN_INTERVAL
&& locations[1]+1 == locations[3]) {
- return true;
- }
- return false;
- }
-
- /**
- * Determine the portion of the current intervals that overlaps with the
- * specified interval. For example, if the current intervals were [1-5, 10-15]
- * and we asked for the overlap with region [4-11], we would get a result
- * [4-5, 10-11].
- *
- * @param begin
- * @param end
- * @return Intervals set defining overlap
- * @throws IllegalArgumentException If begin > end
- */
- public Intervals getIntersection(int begin, int end) {
- if(begin > end) {
- throw new
IllegalArgumentException(CommonPlugin.Util.getString(ErrorMessageKeys.CM_UTIL_ERR_0026));
- }
-
- Intervals overlap = new Intervals();
-
- // Check whether we have any intervals
- if(intervals.size() == 0) {
- return overlap;
- }
-
- // Determine intersection points
- int[] locations = findLocations(intervals, begin, end);
- if(locations[2] == BEFORE_FIRST || locations[0] == AFTER_LAST) {
- // Completely before or after
- return overlap;
- } else if(locations[0] == BETWEEN_INTERVALS && locations[2] ==
BETWEEN_INTERVALS && locations[1] > locations[3]) {
- // Completely between intervals
- return overlap;
- } else if(locations[0] == WITHIN_INTERVAL && locations[2] ==
WITHIN_INTERVAL && locations[1]+1 == locations[3]) {
- // Completely within an interval
- overlap.addInterval(begin, end);
- return overlap;
- } else {
- // There is an overlap of one or more intervals
- int startIndex = locations[1];
- int endIndex = locations[3];
-
- // Determine partial beginning interval
- overlap.addInterval(Math.max(((Integer)intervals.get(startIndex)).intValue(),
begin),
-
Math.min(((Integer)intervals.get(startIndex+1)).intValue(), end) );
-
- // Add all intervals in the middle, if there are any
- int diff = endIndex-startIndex;
- if(diff > 3) {
- Iterator internalIter = intervals.listIterator(startIndex+2);
- int stop = diff-3;
- for(int i=0; i < stop; i=i+2) {
- overlap.addInterval( ((Integer) internalIter.next()).intValue(),
- ((Integer) internalIter.next()).intValue() );
- }
- }
-
- // Determine partial ending interval
- if(diff > 1) {
-
overlap.addInterval(Math.max(((Integer)intervals.get(endIndex-1)).intValue(), begin),
-
Math.min(((Integer)intervals.get(endIndex)).intValue(), end) );
- }
-
- return overlap;
- }
- }
-
- public Intervals getIntersectionIntervals(Intervals intersectionIntervals) {
- Intervals result = new Intervals();
- List intervalList = intersectionIntervals.getIntervals();
- for (Iterator iterator = intervalList.iterator(); iterator.hasNext(); ) {
- int[] interval = (int[]) iterator.next();
- result.addIntervals(getIntersection(interval[0], interval[1]));
- }
- return result;
- }
-
- public Intervals addIntervals(Intervals additionalIntervals) {
- List intervalList = additionalIntervals.getIntervals();
- for (Iterator iterator = intervalList.iterator(); iterator.hasNext(); ) {
- int[] interval = (int[]) iterator.next();
- addInterval(interval[0], interval[1]);
- }
- return this;
- }
-
- /**
- * Return ordered list of intervals representing current intervals.
- * Each element of the returned list is an int[2] representing a
- * begin/end pair of included interval.
- * @return Ordered list of int[2] representing intervals
- */
- public List getIntervals() {
- List list = new ArrayList();
- Iterator iter = intervals.iterator();
- while(iter.hasNext()) {
- list.add(new int[] { ((Integer)iter.next()).intValue(),
((Integer)iter.next()).intValue() });
- }
- return list;
- }
-
- /**
- * Determine there is one interval with no gaps.
- * Returns true for an empty interval.
- * @return Boolean indicator of whether there is one interval.
- */
- public boolean isContiguous() {
- return intervals.size() <= 2;
- }
-
- /**
- * Compares two intervals for equality
- * @param obj Other object
- * @return True if this equal to obj
- */
- public boolean equals(Object obj) {
- if(this == obj) {
- return true;
- }
-
- if(obj == null || ! (obj instanceof Intervals)) {
- return false;
- }
- Intervals other = (Intervals) obj;
-
- List thisIntervals = getIntervals();
- List otherIntervals = other.getIntervals();
-
- if(thisIntervals.size() != otherIntervals.size()) {
- return false;
- }
-
- for(int i=0; i<thisIntervals.size(); i++) {
- int[] thisInt = (int[]) thisIntervals.get(i);
- int[] otherInt = (int[]) otherIntervals.get(i);
-
- if(thisInt[0] != otherInt[0] || thisInt[1] != otherInt[1]) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Returns hash code for the set of intervals. This hash code is
- * based on the intervals and WILL change with any add or remove
- * call. This requires re-hashing the object.
- * @return Hash code
- */
- public int hashCode() {
- if(intervals.size() == 0) {
- return 0;
- }
-
- return intervals.getLast().hashCode();
- }
-
- /**
- * Returns string representation of intervals. This should be used for debugging
only.
- * @return String representing intervals
- */
- public String toString() {
- return intervals.toString();
- }
-
- public int[] getBoundingInterval() {
- int[] result = new int[2];
- if (hasIntervals()) {
- result[0] = ((Integer) intervals.getFirst()).intValue();
- result[1] = ((Integer) intervals.getLast()).intValue();
- } else {
- result[0] = Integer.MIN_VALUE;
- result[1] = Integer.MAX_VALUE;
- }
- return result;
- }
-
- public Intervals copy() {
- return new Intervals(this.intervals);
- }
-}
Deleted:
trunk/common-internal/src/main/java/com/metamatrix/common/util/MultipleRequestConfirmation.java
===================================================================
---
trunk/common-internal/src/main/java/com/metamatrix/common/util/MultipleRequestConfirmation.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/common-internal/src/main/java/com/metamatrix/common/util/MultipleRequestConfirmation.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -1,113 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * This class is used to return to a client the results of a complex management
- * request. The meaning of "result object" and "failured objects" is
dependent upon the context of the method
- * from which this instance is returned.
- * <p>
- * This class uses a Map to hold those objects that were not successfully operated upon
and
- * a corresponding exception; therefore, only objects which have a unique hash code for
different
- * (but unequivalent) instances should be inserted as failed objects.
- */
-public class MultipleRequestConfirmation implements Serializable {
-
- private Object result = null;
- private Map failures = new HashMap();
-
- /**
- * Construct an empty confirmation instance.
- */
- public MultipleRequestConfirmation() {}
-
- /**
- * Set the result of the method request.
- * @param obj the result object
- */
- public void setResult( Object result ) {
- this.result = result;
- }
-
- /**
- * Get the result of the operation.
- * @return the object that contains or is the results for the operation; while
- * this class can contain a null value for the result, the method from which this
- * object is returned should document whether null results are allowed or expected.
- */
- public Object getResult() {
- return result;
- }
-
- /**
- * Add the object that was not successfully operated upon.
- * @param obj the object with which the operation failed.
- * @param e an exception that describes the failure of this object; may be null
- */
- public void addFailure( Object obj, Throwable e ) {
- failures.put(obj,e);
- }
-
- /**
- * Get the object that were not successfully operated upon, and an exception
- * for each that may describe why the operation failed.
- * @return the map keyed upon the objects with which the operation failed; the
- * value for each object key is the exception that was thrown during the operation
- * upon that object, or null if no exception was thrown during the operation
- * but failure still occurred.
- */
- public Map getFailures() {
- return failures;
- }
-
- /**
- * Get the number of objects that were not successfully operated upon.
- * @return the number of objects with which the operation failed.
- */
- public int getFailuresCount() {
- return failures.size();
- }
-
- /*
- * Determine whether there is a result object for this confirmation.
- * @return true if this confirmation object contains a results object, or false
otherwise.
- * @see getResult
- */
- public boolean hasResult() {
- return ( result != null);
- }
-
- /**
- * Determine whether there are any objects that were not successfully operated upon.
- * @return true if at least one operation upon an object was added as failed, or
false otherwise.
- */
- public boolean hasFailures() {
- return !failures.isEmpty();
- }
-
-}
-
Deleted:
trunk/common-internal/src/test/java/com/metamatrix/common/util/TestIntervals.java
===================================================================
---
trunk/common-internal/src/test/java/com/metamatrix/common/util/TestIntervals.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/common-internal/src/test/java/com/metamatrix/common/util/TestIntervals.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -1,842 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.util.LinkedList;
-
-import junit.framework.TestCase;
-
-/**
- */
-public class TestIntervals extends TestCase {
-
- /**
- * Constructor for TestIntervals.
- * @param arg0
- */
- public TestIntervals(String arg0) {
- super(arg0);
- }
-
- private LinkedList toLinkedList(int[] array) {
- LinkedList intervals = new LinkedList();
- for(int i=0; i<array.length; i++) {
- intervals.add(new Integer(array[i]));
- }
- return intervals;
- }
-
- public void helpTestFindLocations(int[] intervalArray, int begin, int end, int[]
expected) {
- int[] actual = Intervals.findLocations(toLinkedList(intervalArray), begin, end);
-
- assertEquals("Unexpected begin type ", expected[0], actual[0]);
//$NON-NLS-1$
- assertEquals("Unexpected begin index ", expected[1], actual[1]);
//$NON-NLS-1$
- assertEquals("Unexpected end type ", expected[2], actual[2]);
//$NON-NLS-1$
- assertEquals("Unexpected end index ", expected[3], actual[3]);
//$NON-NLS-1$
- }
-
- // one range - all before first
- public void testFindLocations1() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.BEFORE_FIRST, 0, Intervals.BEFORE_FIRST,
-1 };
- helpTestFindLocations(intervals, 0, 1, expected);
- }
-
- // one range - all after last
- public void testFindLocations2() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.AFTER_LAST, 0, Intervals.AFTER_LAST, 1 };
- helpTestFindLocations(intervals, 10, 11, expected);
- }
-
- // one range - overlap begin
- public void testFindLocations3() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.BEFORE_FIRST, 0,
Intervals.WITHIN_INTERVAL, 1 };
- helpTestFindLocations(intervals, 0, 7, expected);
- }
-
- // one range - overlap end
- public void testFindLocations4() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 0, Intervals.AFTER_LAST,
1 };
- helpTestFindLocations(intervals, 6, 10, expected);
- }
-
- // one range - within
- public void testFindLocations5() {
- int[] intervals = new int[] { 5, 9 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 0,
Intervals.WITHIN_INTERVAL, 1 };
- helpTestFindLocations(intervals, 6, 7, expected);
- }
-
- // multiple ranges - before, within
- public void testFindLocations6() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.BEFORE_FIRST, 0,
Intervals.WITHIN_INTERVAL, 3 };
- helpTestFindLocations(intervals, 0, 17, expected);
- }
-
- // multiple ranges - within, between
- public void testFindLocations7() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 0,
Intervals.BETWEEN_INTERVALS, 1 };
- helpTestFindLocations(intervals, 6, 12, expected);
- }
-
- // multiple ranges - within, within
- public void testFindLocations8() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 0,
Intervals.WITHIN_INTERVAL, 5 };
- helpTestFindLocations(intervals, 6, 27, expected);
- }
-
- // multiple ranges - between, within
- public void testFindLocations9() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.BETWEEN_INTERVALS, 2,
Intervals.WITHIN_INTERVAL, 5 };
- helpTestFindLocations(intervals, 12, 27, expected);
- }
-
- // multiple ranges - between, after
- public void testFindLocations10() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.BETWEEN_INTERVALS, 2,
Intervals.AFTER_LAST, 5 };
- helpTestFindLocations(intervals, 12, 31, expected);
- }
-
- // multiple ranges - within, after
- public void testFindLocations11() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30 };
- int[] expected = new int[] { Intervals.WITHIN_INTERVAL, 2, Intervals.AFTER_LAST,
5 };
- helpTestFindLocations(intervals, 17, 31, expected);
- }
-
- public void helpTestMergeIntervals(int[] intervalArray, int firstIndex, int
lastIndex, int[] expected) {
- LinkedList intervals = toLinkedList(intervalArray);
- Intervals.mergeIntervals(intervals, firstIndex, lastIndex);
-
- assertEquals("Didn't get expected merge results ",
toLinkedList(expected), intervals); //$NON-NLS-1$
- }
-
- public void testMergeIntervals1() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 5, 10 };
- helpTestMergeIntervals(intervals, 0, 1, expected);
- }
-
- public void testMergeIntervals2() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30, 35, 40 };
- int[] expected = new int[] { 5, 40 };
- helpTestMergeIntervals(intervals, 0, 7, expected);
- }
-
- public void testMergeIntervals3() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30, 35, 40 };
- int[] expected = new int[] { 5, 10, 15, 30, 35, 40 };
- helpTestMergeIntervals(intervals, 2, 5, expected);
- }
-
- public void testMergeIntervals4() {
- int[] intervals = new int[] { 5, 10, 15, 20, 25, 30, 35, 40 };
- int[] expected = new int[] { 5, 10, 15, 40 };
- helpTestMergeIntervals(intervals, 2, 7, expected);
- }
-
- public void helpTestExpandIntervals(int[] intervalArray, int firstIndex, int begin,
int end, int[] expected) {
- LinkedList intervals = toLinkedList(intervalArray);
- Intervals.expandInterval(intervals, firstIndex, begin, end);
-
- assertEquals("Didn't get expected expanded results ",
toLinkedList(expected), intervals); //$NON-NLS-1$
- }
-
- public void testExpandInterval1() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 0, 10 };
- helpTestExpandIntervals(intervals, 0, 0, 9, expected);
- }
-
- public void testExpandInterval2() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 5, 10 };
- helpTestExpandIntervals(intervals, 0, 6, 9, expected);
- }
-
- public void testExpandInterval3() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 0, 15 };
- helpTestExpandIntervals(intervals, 0, 0, 15, expected);
- }
-
- public void testExpandInterval4() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 5, 15 };
- helpTestExpandIntervals(intervals, 0, 6, 15, expected);
- }
-
- public void helpTestCondenseIntervals(int[] intervalArray, int[] expected) {
- LinkedList intervals = toLinkedList(intervalArray);
- Intervals.condense(intervals);
- assertEquals("Didn't get expected condensed results ",
toLinkedList(expected), intervals); //$NON-NLS-1$
- }
-
- public void testCondensedInterval1() {
- int[] intervals = new int[] { 5, 10 };
- int[] expected = new int[] { 5, 10 };
- helpTestCondenseIntervals(intervals, expected);
- }
-
- public void testCondensedInterval2() {
- int[] intervals = new int[] { 5, 10, 11, 15 };
- int[] expected = new int[] { 5, 15 };
- helpTestCondenseIntervals(intervals, expected);
- }
-
- public void testCondensedInterval3() {
- int[] intervals = new int[] { 5, 10, 11, 15, 16, 20 };
- int[] expected = new int[] { 5, 20 };
- helpTestCondenseIntervals(intervals, expected);
- }
-
- public void testCondensedInterval4() {
- int[] intervals = new int[] { 5, 10, 11, 15, 20, 25, 26, 30 };
- int[] expected = new int[] { 5, 15, 20, 30 };
- helpTestCondenseIntervals(intervals, expected);
- }
-
- public void testAddIntervalDistinct() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- String expected = "[5, 10, 15, 20, 25, 30]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalBeforeBeginning() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(0, 1);
- String expected = "[0, 1, 5, 10]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalAtBeginning() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(2, 5);
- String expected = "[2, 10]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalAtEnd() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(9, 15);
- String expected = "[5, 15]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalOverlapping1() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(7, 15);
- i.addInterval(12, 20);
- String expected = "[5, 20]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalOverlapping2() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(7, 15);
- i.addInterval(2, 5);
- String expected = "[2, 15]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalOverlapping3() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(6, 19);
- String expected = "[5, 20]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalExpand() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(2, 20);
- String expected = "[2, 20]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalInsert() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(12, 13);
- String expected = "[5, 10, 12, 13, 15, 20]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalWithin() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(6, 7);
- String expected = "[5, 10]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalBetweenBetween() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- i.addInterval(12, 22);
- String expected = "[5, 10, 12, 22, 25, 30]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalBetweenWithin() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- i.addInterval(12, 27);
- String expected = "[5, 10, 12, 30]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalComplex() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- i.addInterval(12, 27);
- i.addInterval(11, 11);
- String expected = "[5, 30]"; //$NON-NLS-1$
-
- assertEquals("Invalid after adds ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testAddIntervalError() {
- Intervals i = new Intervals();
- try {
- i.addInterval(5, 3);
- fail("Expected to get IllegalArgumentException when adding illegal
interval"); //$NON-NLS-1$
- } catch(IllegalArgumentException e) {
- }
- }
-
- public void testRemoveInterval1() {
- Intervals i = new Intervals();
- i.removeInterval(0, 10);
- String expected = "[]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval2() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(0, 2);
- String expected = "[5, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval3() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(0, 5);
- String expected = "[6, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval4() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(0, 6);
- String expected = "[7, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval5() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(4, 8);
- String expected = "[9, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval6() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(7, 10);
- String expected = "[5, 6]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval7() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(7, 11);
- String expected = "[5, 6]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval8() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(5, 10);
- String expected = "[]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval9() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.removeInterval(6, 9);
- String expected = "[5, 5, 10, 10]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval10() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.removeInterval(12, 14);
- String expected = "[5, 10, 15, 20]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval11() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.removeInterval(8, 17);
- String expected = "[5, 7, 18, 20]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval12() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.removeInterval(12, 17);
- String expected = "[5, 10, 18, 20]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval13() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.removeInterval(7, 25);
- String expected = "[5, 6]"; //$NON-NLS-1$
- assertEquals("Invalid after remove ", expected, i.toString());
//$NON-NLS-1$
- }
-
- public void testRemoveInterval14() {
- Intervals i = new Intervals();
- i.addInterval(2, 3);
- i.removeInterval(0, 4);
- assertEquals("Invalid after remove ", "[]", i.toString());
//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRemoveInterval15() {
- Intervals i = new Intervals();
- i.addInterval(2, 3);
- i.removeInterval(4, 5);
- assertEquals("Invalid after remove ", "[2, 3]",
i.toString()); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRemoveIntervalInvalid() {
- Intervals i = new Intervals();
- try {
- i.removeInterval(1, 0);
- fail("Expected IllegalArgumentException when removing invalid
interval"); //$NON-NLS-1$
- } catch(IllegalArgumentException e) {
- }
- }
-
- public void testContainsInterval1() {
- Intervals i = new Intervals();
- assertEquals("Contains is wrong ", false, i.containsInterval(0, 1));
//$NON-NLS-1$
- }
-
- public void testContainsInterval2() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", true, i.containsInterval(5, 10));
//$NON-NLS-1$
- }
-
- public void testContainsInterval3() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", true, i.containsInterval(6, 9));
//$NON-NLS-1$
- }
-
- public void testContainsInterval4() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", false, i.containsInterval(1, 2));
//$NON-NLS-1$
- }
-
- public void testContainsInterval5() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", false, i.containsInterval(20, 21));
//$NON-NLS-1$
- }
-
- public void testContainsInterval6() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", false, i.containsInterval(0, 7));
//$NON-NLS-1$
- }
-
- public void testContainsInterval7() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- assertEquals("Contains is wrong ", false, i.containsInterval(7, 20));
//$NON-NLS-1$
- }
-
- public void testContainsInterval8() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(12, 15);
- assertEquals("Contains is wrong ", false, i.containsInterval(5, 15));
//$NON-NLS-1$
- }
-
- public void testContainsIntervalInvalid() {
- Intervals i = new Intervals();
- try {
- i.containsInterval(1, 0);
- fail("Expected IllegalArgumentException when checking containment of
invalid interval"); //$NON-NLS-1$
- } catch(IllegalArgumentException e) {
- }
- }
-
- public void testIntersection1() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- Intervals expected = new Intervals();
- assertEquals("Intersection is wrong ", expected, i.getIntersection(0,
1)); //$NON-NLS-1$
- }
-
- public void testIntersection2() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- Intervals expected = new Intervals();
- expected.addInterval(5, 7);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(0,
7)); //$NON-NLS-1$
- }
-
- public void testIntersection3() {
- Intervals i = new Intervals();
- i.addInterval(5,10);
- Intervals expected = new Intervals();
- expected.addInterval(5, 10);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(0,
12)); //$NON-NLS-1$
- }
- public void testIntersection4() {
- Intervals i = new Intervals();
- i.addInterval(5,10);
- Intervals expected = new Intervals();
- expected.addInterval(6, 9);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(6,
9)); //$NON-NLS-1$
- }
-
- public void testIntersection5() {
- Intervals i = new Intervals();
- i.addInterval(5,10);
- Intervals expected = new Intervals();
- expected.addInterval(6, 10);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(6,
12)); //$NON-NLS-1$
- }
-
- public void testIntersection6() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(6, 10);
- expected.addInterval(15, 16);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(6,
16)); //$NON-NLS-1$
- }
-
- public void testIntersection7() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(6, 10);
- expected.addInterval(15, 20);
- expected.addInterval(25, 26);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(6,
26)); //$NON-NLS-1$
- }
-
- public void testIntersection8() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(5, 10);
- expected.addInterval(15, 20);
- expected.addInterval(25, 30);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(1,
35)); //$NON-NLS-1$
- }
-
- public void testIntersection9() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(15, 20);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(11,
24)); //$NON-NLS-1$
- }
-
- public void testIntersection10() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(15, 20);
- expected.addInterval(25, 26);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(11,
26)); //$NON-NLS-1$
- }
-
- public void testIntersection11() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- i.addInterval(25, 30);
- Intervals expected = new Intervals();
- expected.addInterval(25, 30);
- assertEquals("Intersection is wrong ", expected, i.getIntersection(24,
40)); //$NON-NLS-1$
- }
-
- public void testIntersection12() {
- Intervals i = new Intervals();
- Intervals expected = new Intervals();
- assertEquals("Intersection is wrong ", expected, i.getIntersection(5,
10)); //$NON-NLS-1$
- }
-
- public void testIntersection13() {
- Intervals i = new Intervals();
- i.addInterval(5, 10);
- i.addInterval(15, 20);
- Intervals expected = new Intervals();
- assertEquals("Intersection is wrong ", expected,
i.getIntersection(11,12)); //$NON-NLS-1$
- }
-
- public void testIntersectionInvalid() {
- Intervals i = new Intervals();
- try {
- i.getIntersection(1, 0);
- fail("Expected IllegalArgumentException when checking containment of
invalid interval"); //$NON-NLS-1$
- } catch(IllegalArgumentException e) {
- }
- }
-
- public void testEquals1() {
- Intervals i1 = new Intervals();
- i1.addInterval(5, 10);
- i1.addInterval(15, 20);
-
- Intervals i2 = new Intervals();
- i2.addInterval(5, 10);
- i2.addInterval(15, 20);
-
- assertTrue("Equals is wrong ", i1.equals(i2)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", i2.equals(i1)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", i1.hashCode() == i2.hashCode());
//$NON-NLS-1$
- }
-
- public void testEquals2() {
- Intervals i1 = new Intervals();
- i1.addInterval(5, 10);
-
- Intervals i2 = new Intervals();
- i2.addInterval(5, 11);
-
- assertTrue("Equals is wrong ", !i1.equals(i2)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", !i2.equals(i1)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", i1.hashCode() != i2.hashCode());
//$NON-NLS-1$
- }
-
- public void testEquals3() {
- Intervals i1 = new Intervals();
- i1.addInterval(5, 10);
- i1.addInterval(14, 20);
-
- Intervals i2 = new Intervals();
- i2.addInterval(5, 10);
- i2.addInterval(15, 20);
-
- assertTrue("Equals is wrong ", !i1.equals(i2)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", !i2.equals(i1)); //$NON-NLS-1$
- }
-
- public void testEquals4() {
- Intervals i1 = new Intervals();
- i1.addInterval(5, 10);
- i1.addInterval(15, 20);
-
- Intervals i2 = new Intervals();
- i2.addInterval(5, 10);
-
- assertTrue("Equals is wrong ", !i1.equals(i2)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", !i2.equals(i1)); //$NON-NLS-1$
- assertTrue("Equals is wrong ", i1.hashCode() != i2.hashCode());
//$NON-NLS-1$
- }
-
- public void testEquals5() {
- Intervals i1 = new Intervals();
- assertTrue("Equals is wrong ", i1.equals(i1)); //$NON-NLS-1$
- }
-
- public void testEquals6() {
- Intervals i1 = new Intervals();
- assertTrue("Equals is wrong ", ! i1.equals(null)); //$NON-NLS-1$
- }
-
- public void testEquals7() {
- Intervals i1 = new Intervals();
- assertTrue("Equals is wrong ", ! i1.equals("abc"));
//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testRemoveIntervals() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- Intervals y = new Intervals();
- y.addInterval(21, 30);
- x.removeIntervals(y);
- assertEquals("[1, 20, 31, 100]", x.toString()); //$NON-NLS-1$
- }
-
- public void testRemoveMultipleIntervals() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- Intervals y = new Intervals();
- y.addInterval(21, 30);
- y.addInterval(41, 50);
- x.removeIntervals(y);
- assertEquals("[1, 20, 31, 40, 51, 100]", x.toString()); //$NON-NLS-1$
- }
-
- public void testGetBoundingInterval() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- int[] result = x.getBoundingInterval();
- assertEquals(1, result[0]);
- assertEquals(100, result[1]);
- }
-
- public void testGetBoundingIntervalWithMultipleIntervals() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- x.addInterval(200, 300);
- int[] result = x.getBoundingInterval();
- assertEquals(1, result[0]);
- assertEquals(300, result[1]);
- }
-
- public void testGetBoundingIntervalWithNoIntervals() {
- Intervals x = new Intervals();
- int[] result = x.getBoundingInterval();
- assertEquals(Integer.MIN_VALUE, result[0]);
- assertEquals(Integer.MAX_VALUE, result[1]);
- }
-
- public void testGetIntersectionIntervals() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- Intervals y = new Intervals();
- y.addInterval(10, 20);
- assertEquals("[10, 20]", x.getIntersectionIntervals(y).toString());
//$NON-NLS-1$
-
- }
-
- public void testGetIntersectionIntervalsMultiple() {
- Intervals x = new Intervals();
- x.addInterval(1, 100);
- x.addInterval(201, 300);
- Intervals y = new Intervals();
- y.addInterval(90, 210);
- y.addInterval(290, 300);
- assertEquals("[90, 100, 201, 210, 290, 300]",
x.getIntersectionIntervals(y).toString()); //$NON-NLS-1$
- }
-
- public void testConstructorTakesInterval() {
- Intervals x = new Intervals(1, 100);
- assertEquals("[1, 100]", x.toString()); //$NON-NLS-1$
- }
-
- public void testCopy() {
- Intervals x = new Intervals(1, 10);
- x.addInterval(20, 30);
- Intervals y = x.copy();
- assertEquals("[1, 10, 20, 30]", y.toString()); //$NON-NLS-1$
- x.removeInterval(5, 25);
- //changing x should not affect y
- assertEquals("[1, 10, 20, 30]", y.toString()); //$NON-NLS-1$
-
- }
-
- public void testIsContiguous() {
- Intervals x = new Intervals();
- x.addInterval(5, 10);
- x.addInterval(0, 10);
- assertTrue( x.isContiguous() );
- }
-
- public void testIsNotContiguous() {
- Intervals x = new Intervals();
- x.addInterval(5, 10);
- x.addInterval(1, 3);
- assertFalse( x.isContiguous() );
- }
-
- public void testEmptyIntervalsIsContiguous() {
- Intervals x = new Intervals();
- assertTrue( x.isContiguous() );
- }
-}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CacheResults.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CacheResults.java 2009-05-07
21:28:59 UTC (rev 884)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CacheResults.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -22,6 +22,7 @@
package org.teiid.dqp.internal.cache;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -38,15 +39,11 @@
private Map paramValues;
private boolean isFinal;
- private int firstRow;
+ private int firstRow = 1;
//size of this results in memory
private long size= -1;
private int finalRow = -1;
- //hold temp results
- private CursorReceiverWindowBuffer tempResults;
- private Object requestID;
-
public CacheResults(List[] results, int firstRow, boolean isFinal){
this(results, null, firstRow, isFinal);
}
@@ -125,67 +122,27 @@
//add the results to the existing one, this is used
//when building the batched results
- boolean addResults(CacheResults cacheResults, Object requestID){
- int firstRow = cacheResults.getFirstRow() - 1;
- boolean isFinal = cacheResults.isFinal();
- List[] results = cacheResults.getResults();
+ boolean addResults(CacheResults cacheResults){
+ if (this.firstRow + results.length != cacheResults.getFirstRow()) {
+ throw new
MetaMatrixRuntimeException(DQPPlugin.Util.getString("ResultSetCache.1"));//$NON-NLS-1$
+ }
this.size += cacheResults.size;
- if(this.requestID == null){
- //first batch
- if(firstRow != 0){
- //the previous batch has been removed
- return false;
- }
-
- if(isFinal){
- this.results = results;
- this.command = cacheResults.getCommand();
- this.analysisRecord = cacheResults.getAnalysisRecord();
- this.firstRow = 1;
- this.isFinal = true;
- this.finalRow = this.results.length;
- return true;
- }
-
- //first time adding the results
- this.requestID = requestID;
- this.tempResults = new CursorReceiverWindowBuffer();
+ List[] batchResults = cacheResults.getResults();
+ if (results == null) {
+ this.results = batchResults;
+ } else if (batchResults.length > 0){
+ this.results = Arrays.copyOf(this.results, this.results.length +
batchResults.length);
+ System.arraycopy(batchResults, 0, this.results, this.results.length -
batchResults.length, batchResults.length);
}
-
- //check whether it is from same command
- if(!requestID.equals(this.requestID)){
- //could happen to connector
- return true;
- }
- if(results != null && results.length > 0){
- tempResults.add(new int[]{firstRow, firstRow + results.length - 1}, results);
- }
- if(isFinal){
- if(!tempResults.getContents().isContiguous()){
- //should not come here
- throw new
MetaMatrixRuntimeException(DQPPlugin.Util.getString("ResultSetCache.1"));//$NON-NLS-1$
- }
- this.results = tempResults.getAllRows();
+ if(cacheResults.isFinal()){
this.command = cacheResults.getCommand();
this.analysisRecord = cacheResults.getAnalysisRecord();
- this.paramValues = cacheResults.getParamValues();
this.firstRow = 1;
this.isFinal = true;
this.finalRow = this.results.length;
-
- //cleanup temp data
- this.tempResults = null;
- this.requestID = null;
}
return true;
}
- //whether we have got all the batches (including the chunks if it is lob)
- boolean hasAllResults(){
- if(!this.isFinal){
- return false;
- }
- return true;
- }
}
Deleted:
trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CursorReceiverWindowBuffer.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CursorReceiverWindowBuffer.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/cache/CursorReceiverWindowBuffer.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -1,116 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.dqp.internal.cache;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import com.metamatrix.common.util.Intervals;
-
-/**
- * Used on the client side of the JDBC driver. Keeps track of batches of rows retrieved
from the server.
- * Removes batches based on the decisions of the ReceiverWindow.
- */
-public class CursorReceiverWindowBuffer {
- Intervals bufferIntervals = new Intervals();
- /** Caches the bounding range for the previous call to getRow(). Typically, the next
call to getRow() will be lie within these bounds. */
- private int[] currentIntervalsBoundingRange;
- /** Caches the data for the previous call to getRow(). Typically, the next row
required will be in this cache. */
- private List[] currentIntervalsData;
- private Map buffer = new HashMap();
-
- public void add(int[] range, List[] data) {
- if (range[1] >= range[0]) {
- bufferIntervals.addInterval(range[0], range[1]);
- buffer.put(new Intervals(range[0], range[1]), data);
- }
- }
-
- public List getRow(int index) {
- if (currentIntervalsBoundingRange != null &&
currentIntervalsBoundingRange[0] <= index && currentIntervalsBoundingRange[1]
>= index) {
- return currentIntervalsData[index-currentIntervalsBoundingRange[0]];
- }
- Iterator iterator = buffer.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry entry = (Map.Entry)iterator.next();
- Intervals i = (Intervals) entry.getKey();
- if (i.containsInterval(index, index)) {
- currentIntervalsData = (List[]) entry.getValue();
- currentIntervalsBoundingRange = i.getBoundingInterval();
- return currentIntervalsData[index-currentIntervalsBoundingRange[0]];
- }
- }
- currentIntervalsData = null;
- currentIntervalsBoundingRange=null;
- throw new IndexOutOfBoundsException();
- }
-
- /*
- * @see com.metamatrix.common.window.ReceiverWindowBuffer#getContents()
- */
- public Intervals getContents() {
- return bufferIntervals.copy();
- }
-
- /*
- * @see
com.metamatrix.common.window.ReceiverWindowBuffer#removeFromCache(com.metamatrix.common.util.Intervals)
- */
- public void removeFromCache(Intervals toRemove) {
- if (toRemove.hasIntervals()) {
- Iterator iterator = buffer.keySet().iterator();
- while (iterator.hasNext()) {
- Intervals i = (Intervals) iterator.next();
- int[] range = i.getBoundingInterval();
- if (toRemove.containsInterval(range[0], range[1])) {
- iterator.remove();
- bufferIntervals.removeInterval(range[0], range[1]);
- }
- }
- }
- }
-
- public List[] getAllRows() {
- if (!bufferIntervals.isContiguous()) {
- throw new IndexOutOfBoundsException();
- }
- int baseIndex = bufferIntervals.getBoundingInterval()[0];
- int size = bufferIntervals.getBoundingInterval()[1] - baseIndex + 1;
- List[] result = new List[size];
- for (int i=0; i<size; i++) {
- result[i+baseIndex] = getRow(i);
- }
- return result;
- }
-
-
- public boolean containsInterval(int begin, int end) {
- if (currentIntervalsBoundingRange != null &&
- currentIntervalsBoundingRange[0] <= begin &&
- currentIntervalsBoundingRange[1] >= end) {
- return true;
- }
- return bufferIntervals.containsInterval(begin, end);
- }
-}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/cache/ResultSetCache.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/cache/ResultSetCache.java 2009-05-07
21:28:59 UTC (rev 884)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/cache/ResultSetCache.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -33,11 +33,39 @@
import com.metamatrix.cache.Cache.Type;
import com.metamatrix.cache.CacheConfiguration.Policy;
import com.metamatrix.common.util.PropertiesUtils;
+import com.metamatrix.core.util.HashCodeUtil;
/**
* Used to cache ResultSet based on the exact match of sql string.
*/
public class ResultSetCache {
+
+ static class TempKey {
+ CacheID cacheID;
+ Object requestID;
+
+ public TempKey(CacheID cacheID, Object requestID) {
+ this.cacheID = cacheID;
+ this.requestID = requestID;
+ }
+ @Override
+ public int hashCode() {
+ return HashCodeUtil.hashCode(cacheID.hashCode(), requestID.hashCode());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof TempKey)) {
+ return false;
+ }
+ TempKey other = (TempKey) obj;
+ return (cacheID.equals(other.cacheID) && requestID.equals(other.requestID));
+ }
+ }
+
//configurable parameters
public static final String RS_CACHE_MAX_SIZE = "maxSize"; //$NON-NLS-1$
public static final String RS_CACHE_MAX_AGE = "maxAge"; //$NON-NLS-1$
@@ -49,7 +77,7 @@
private Cache<CacheID, CacheResults> cache;
private String scope;
- private Map<CacheID, CacheResults> tempBatchResults = new HashMap<CacheID,
CacheResults>();
+ private Map<TempKey, CacheResults> tempBatchResults = new HashMap<TempKey,
CacheResults>();
private int maxSize = 50 * 1024 * 1024; //bytes
private int maxAge = 60 * 60; // seconds
private int maxEntries = 20 * 1024;
@@ -127,30 +155,30 @@
long currentCacheSize = getCacheSize();
+ TempKey key = new TempKey(cacheID, requestID);
//do not cache if it is over cache limit
if(isOverCacheLimit(currentCacheSize, cacheResults.getSize())){
- removeTempResults(cacheID);
+ removeTempResults(key);
return false;
}
synchronized(tempBatchResults){
- CacheResults savedResults = tempBatchResults.get(cacheID);
+ CacheResults savedResults = tempBatchResults.get(key);
if(savedResults == null){
- savedResults = new CacheResults(null, cacheResults.getElements(), 1, false);
- tempBatchResults.put(cacheID, savedResults);
- }
- if(!savedResults.addResults(cacheResults, requestID)){
- removeTempResults(cacheID);
+ savedResults = cacheResults;
+ tempBatchResults.put(key, cacheResults);
+ } else if(!savedResults.addResults(cacheResults)){
+ removeTempResults(key);
return false;
}
//do not cache if it is over cache limit
if(isOverCacheLimit(currentCacheSize, savedResults.getSize())){
- removeTempResults(cacheID);
+ removeTempResults(key);
return false;
}
- if(savedResults.hasAllResults()){
+ if(savedResults.isFinal()){
tempBatchResults.remove(cacheID);
cacheID.setMemorySize(savedResults.getSize());
cache.put(cacheID, savedResults);
@@ -169,8 +197,12 @@
}
return false;
}
+
+ public void removeTempResults(CacheID cacheID, Object requestID){
+ removeTempResults(new TempKey(cacheID, requestID));
+ }
- public void removeTempResults(CacheID cacheID){
+ public void removeTempResults(TempKey cacheID){
synchronized(tempBatchResults){
tempBatchResults.remove(cacheID);
}
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItemFactory.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItemFactory.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/ConnectorWorkItemFactory.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -112,7 +112,7 @@
public void receiveResults(AtomicResultsMessage results) {
boolean isFinal = results.getFinalRow() >= 0;
if (results.isRequestClosed()) {
- rsCache.removeTempResults(cacheID);
+ rsCache.removeTempResults(cacheID, requestId);
} else {
CacheResults cr = new CacheResults(results.getResults(), firstRow, isFinal);
firstRow += results.getResults().length;
@@ -123,7 +123,7 @@
@Override
public void exceptionOccurred(Throwable e) {
- rsCache.removeTempResults(cacheID);
+ rsCache.removeTempResults(cacheID, requestId);
actual.exceptionOccurred(e);
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -222,7 +222,7 @@
LogManager.logDetail(LogConstants.CTX_DQP, e, "############# PW EXITING
on", requestID, "- error occurred ###########"); //$NON-NLS-1$
//$NON-NLS-2$
//if there is a cache, remove temp results if there is any
if(this.rsCache != null){
- rsCache.removeTempResults(cid);
+ rsCache.removeTempResults(cid, requestID);
}
if (!isCanceled()) {
Deleted:
trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestCursorReceiverWindowBuffer.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestCursorReceiverWindowBuffer.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestCursorReceiverWindowBuffer.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -1,93 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.dqp.internal.cache;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.teiid.dqp.internal.cache.CursorReceiverWindowBuffer;
-
-import junit.framework.TestCase;
-import com.metamatrix.common.util.Intervals;
-
-public class TestCursorReceiverWindowBuffer extends TestCase {
- CursorReceiverWindowBuffer buffer = new CursorReceiverWindowBuffer();
-
- public void test() {
- add(0,100);
- }
-
- private void add(int start, int end) {
- int[] range = new int[2];
- range[0] = start;
- range[1] = end;
- List[] data = new List[end+1-start];
- for (int i=0; i<end+1-start; i++) {
- data[i] = new ArrayList();
- data[i].add(new Integer(i+start));
- }
- buffer.add(range, data);
- }
-
- public void testGetRow() {
- add(1,100);
- checkRow(50);
- }
-
- public void testGetRowNotZeroBased() {
- add(101,200);
- checkRow(150);
- }
-
- public void testGetRowMultipleBatches() {
- add(1,100);
- add(101,200);
- checkRow(50);
- checkRow(150);
- }
-
- public void testForgetBatchs() {
- add(1,100);
- buffer.removeFromCache(new Intervals(1,100));
- assertEquals("[]", buffer.getContents().toString()); //$NON-NLS-1$
- }
-
- public void testCantForgetBatch() {
- add(1,100);
- buffer.removeFromCache(new Intervals(50,100));
- assertEquals("[1, 100]", buffer.getContents().toString());
//$NON-NLS-1$
- }
-
- public void testForgetTwoBatches() {
- add(1,100);
- add(101,200);
- buffer.removeFromCache(new Intervals(1,200));
- assertEquals("[]", buffer.getContents().toString()); //$NON-NLS-1$
- }
-
- private void checkRow(int index) {
- Integer data = (Integer) buffer.getRow(index).get(0);
- assertEquals(index, data.intValue());
- }
-
-}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestResultSetCache.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestResultSetCache.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/cache/TestResultSetCache.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -22,26 +22,21 @@
package org.teiid.dqp.internal.cache;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import org.teiid.dqp.internal.cache.CacheID;
-import org.teiid.dqp.internal.cache.CacheResults;
-import org.teiid.dqp.internal.cache.ResultSetCache;
+import org.junit.Test;
-import junit.framework.TestCase;
-
import com.metamatrix.cache.FakeCache.FakeCacheFactory;
import com.metamatrix.common.buffer.impl.SizeUtility;
+import com.metamatrix.core.MetaMatrixRuntimeException;
-public class TestResultSetCache extends TestCase{
-
- public TestResultSetCache(final String name) {
- super(name);
- }
+public class TestResultSetCache {
- public void testSetAndGetResultsForSession() throws Exception{
+ @Test public void testSetAndGetResultsForSession() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -53,11 +48,11 @@
CacheID id2 = new CacheID("12346", "select * from table2");
//$NON-NLS-1$//$NON-NLS-2$
List[] result2 = new List[]{new ArrayList()};
cache.setResults(id2, new CacheResults(result2, 1, true), "req2" );
//$NON-NLS-1$
- assertEquals(cache.getResults(id1, new int[]{1, 500}).getResults(), result1);
- assertEquals(cache.getResults(id2, new int[]{1, 500}).getResults(), result2);
+ assertEquals(result1, cache.getResults(id1, new int[]{1, 500}).getResults());
+ assertEquals(result2, cache.getResults(id2, new int[]{1, 500}).getResults());
}
- public void testSetAndGetResultsForVDB() throws Exception{
+ @Test public void testSetAndGetResultsForVDB() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -73,7 +68,7 @@
assertEquals(cache.getResults(id2, new int[]{1, 500}).getResults(), result2);
}
-// public void testRemoveConnection() throws Exception{
+// @Test public void testRemoveConnection() throws Exception{
// Properties props = new Properties();
// props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
// props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -89,7 +84,7 @@
// assertNull(cache.getResults(id1, new int[]{0, 500})); //$NON-NLS-1$
// }
//
-// public void testRemoveVDB() throws Exception{
+// @Test public void testRemoveVDB() throws Exception{
// Properties props = new Properties();
// props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
// props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -105,7 +100,7 @@
// assertNull(cache.getResults(id1, new int[]{0, 500})); //$NON-NLS-1$
// }
- public void testClearAllCache() throws Exception{
+ @Test public void testClearAllCache() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -121,7 +116,7 @@
assertNull(cache.getResults(id1, new int[]{1, 500}));
}
- public void testSetAndGetResultsForSession1() throws Exception{
+ @Test public void testSetAndGetResultsForSession1() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -142,7 +137,7 @@
assertEquals(cache.getResults(id1, new int[]{1, 2}).getResults()[0], row1);
}
- public void testSetAndGetResultsForSession2() throws Exception{
+ @Test public void testSetAndGetResultsForSession2() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -167,7 +162,7 @@
assertEquals(cache.getResults(id1, new int[]{1, 2}).getResults()[0], row1);
}
- public void testMaxSize() throws Exception{
+ @Test public void testMaxSize() throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "1"); //$NON-NLS-1$
@@ -206,7 +201,7 @@
}
- public void testComputeSize() throws Exception{
+ @Test public void testComputeSize() throws Exception{
int cnt = 1000000;
List[] results = new List[cnt];
List row = new ArrayList();
@@ -229,7 +224,7 @@
assertEquals(size, result.getSize());
}
- public void testSetDifferentReqID() throws Exception{
+ @Test(expected=MetaMatrixRuntimeException.class) public void testBatchNotContiguous()
throws Exception{
Properties props = new Properties();
props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
@@ -237,31 +232,9 @@
ResultSetCache cache = new ResultSetCache(props, new FakeCacheFactory());
CacheID id1 = new CacheID("vdb1", "select * from table1");
//$NON-NLS-1$//$NON-NLS-2$
CacheResults result1 = createResults(1000, 1, 100, false);
- CacheResults result2 = createResults(3000, 101, 250, false);
- CacheResults result3 = createResults(2000, 101, 200, true);
- cache.setResults(id1, result1 , "req1"); //$NON-NLS-1$
- cache.setResults(id1, result2, "req2" ); //$NON-NLS-1$
- cache.setResults(id1, result3, "req1" ); //$NON-NLS-1$
- assertEquals(cache.getResults(id1, new int[]{1, 500}).getFinalRow(), 300);
- assertEquals(cache.getResults(id1, new int[]{1, 500}).getResults().length, 300);
- }
-
- public void testBatchNotContiguous() throws Exception{
- Properties props = new Properties();
- props.setProperty(ResultSetCache.RS_CACHE_MAX_AGE, "0"); //$NON-NLS-1$
- props.setProperty(ResultSetCache.RS_CACHE_MAX_SIZE, "0"); //$NON-NLS-1$
- props.setProperty(ResultSetCache.RS_CACHE_SCOPE,
ResultSetCache.RS_CACHE_SCOPE_CONN);
- ResultSetCache cache = new ResultSetCache(props, new FakeCacheFactory());
- CacheID id1 = new CacheID("vdb1", "select * from table1");
//$NON-NLS-1$//$NON-NLS-2$
- CacheResults result1 = createResults(1000, 1, 100, false);
CacheResults result3 = createResults(2000, 102, 200, true);
cache.setResults(id1, result1 , "req1"); //$NON-NLS-1$
- try{
- cache.setResults(id1, result3, "req1" ); //$NON-NLS-1$
- fail("Expect an exception but did not get."); //$NON-NLS-1$
- }catch(Exception e){
- //expect an exception
- }
+ cache.setResults(id1, result3, "req1" ); //$NON-NLS-1$
}
}
Modified: trunk/soap/src/main/java/com/metamatrix/soap/handler/ActionUpdateHandler.java
===================================================================
---
trunk/soap/src/main/java/com/metamatrix/soap/handler/ActionUpdateHandler.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/soap/src/main/java/com/metamatrix/soap/handler/ActionUpdateHandler.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -42,8 +42,8 @@
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.axis2.transport.http.HTTPConstants;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.soap.exceptions.SOAPProcessingException;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
/**
Modified:
trunk/soap/src/main/java/com/metamatrix/soap/service/DataServiceWebServiceImpl.java
===================================================================
---
trunk/soap/src/main/java/com/metamatrix/soap/service/DataServiceWebServiceImpl.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/soap/src/main/java/com/metamatrix/soap/service/DataServiceWebServiceImpl.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -43,7 +43,6 @@
import com.metamatrix.admin.api.objects.LogConfiguration;
import com.metamatrix.common.util.ByteArrayHelper;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.jdbc.api.SQLStates;
import com.metamatrix.soap.SOAPPlugin;
@@ -51,6 +50,7 @@
import com.metamatrix.soap.security.Credential;
import com.metamatrix.soap.sqlquerywebservice.log.LogUtil;
import com.metamatrix.soap.util.EndpointUriTranslatorStrategyImpl;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
/**
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java
===================================================================
---
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMDiscoverWSDLServlet.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -35,12 +35,12 @@
import com.metamatrix.admin.api.exception.AdminException;
import com.metamatrix.api.exception.security.LogonException;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.log.FileLogWriter;
import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.soap.SOAPPlugin;
import com.metamatrix.soap.object.MMServerInfo;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
/**
Modified:
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java
===================================================================
---
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetVDBResourceServlet.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -48,7 +48,6 @@
import org.apache.log4j.Logger;
import com.metamatrix.common.api.MMURL;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.CoreConstants;
import com.metamatrix.core.log.FileLogWriter;
import com.metamatrix.core.log.LogListener;
@@ -57,6 +56,7 @@
import com.metamatrix.soap.SOAPPlugin;
import com.metamatrix.soap.util.ErrorMessageKeys;
import com.metamatrix.soap.util.SOAPConstants;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java 2009-05-07
21:28:59 UTC (rev 884)
+++ trunk/soap/src/main/java/com/metamatrix/soap/servlet/MMGetWSDLServlet.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -34,13 +34,13 @@
import org.apache.log4j.Logger;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.log.FileLogWriter;
import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.core.util.StringUtil;
import com.metamatrix.soap.SOAPPlugin;
import com.metamatrix.soap.util.ErrorMessageKeys;
import com.metamatrix.soap.util.SOAPConstants;
+import com.metamatrix.soap.util.WSDLServletUtil;
import com.metamatrix.soap.util.WebServiceUtil;
/**
Modified: trunk/soap/src/main/java/com/metamatrix/soap/servlet/WSDLURLGenerator.java
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/servlet/WSDLURLGenerator.java 2009-05-07
21:28:59 UTC (rev 884)
+++ trunk/soap/src/main/java/com/metamatrix/soap/servlet/WSDLURLGenerator.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -43,13 +43,13 @@
import org.apache.log4j.Logger;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.core.log.FileLogWriter;
import com.metamatrix.core.log.LogListener;
import com.metamatrix.core.log.MessageLevel;
import com.metamatrix.soap.SOAPPlugin;
import com.metamatrix.soap.util.ErrorMessageKeys;
import com.metamatrix.soap.util.SOAPConstants;
+import com.metamatrix.soap.util.WSDLServletUtil;
/**
* Servlet to build the WSDL URL for the specified VDB
Modified:
trunk/soap/src/main/java/com/metamatrix/soap/util/EndpointUriTranslatorStrategyImpl.java
===================================================================
---
trunk/soap/src/main/java/com/metamatrix/soap/util/EndpointUriTranslatorStrategyImpl.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/soap/src/main/java/com/metamatrix/soap/util/EndpointUriTranslatorStrategyImpl.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -30,7 +30,6 @@
import org.apache.axis2.context.MessageContext;
-import com.metamatrix.common.util.WSDLServletUtil;
import com.metamatrix.soap.exceptions.SOAPProcessingException;
import com.metamatrix.soap.handler.ActionUpdateHandler;
import com.metamatrix.soap.service.DataServiceInfo;
Copied: trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java (from rev
872, trunk/common-core/src/main/java/com/metamatrix/common/util/WSDLServletUtil.java)
===================================================================
--- trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java
(rev 0)
+++ trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.soap.util;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Constants pertaining to WSDL servlet execution.
+ *
+ * @since 4.2
+ */
+
+public class WSDLServletUtil {
+
+ /**
+ * General keys
+ */
+ public static final String SERVER_URL_KEY = "ServerURL"; //$NON-NLS-1$
+
+ public static final String SECURE_PROTOCOL = "Secure"; //$NON-NLS-1$
+
+ public static final String VDB_NAME_KEY = "VDBName"; //$NON-NLS-1$
+
+ public static final String VDB_VERSION_KEY = "VDBVersion"; //$NON-NLS-1$
+
+ public static final String ADD_PROPS = "AdditionalProperties"; //$NON-NLS-1$
+
+ public static final String TXN_AUTO_WRAP = "txnAutoWrap"; //$NON-NLS-1$
+
+ public static final String ADD_EXEC_PROPS = "AddExecProperties";
//$NON-NLS-1$
+
+ public static final String MM_WEBSERVICE_QUERY_TIMEOUT =
"com.metamatrix.webservice.querytimeout"; //$NON-NLS-1$
+
+ public static final String DISCOVERED_WSDL = "discovered_wsdl"; //$NON-NLS-1$
+
+ /*
+ * This is the parameter that will tell this servlet when the web service endpoint as
defined in WSDL served up by this
+ * servlet will use the HTTP vs HTTPS protocol.
+ */
+ public static final String HTTP_TYPE_PARAMETER_KEY = "httptype";
//$NON-NLS-1$
+
+ /*
+ * This is the value of the httptype URL request param that will indicate that the
returned WSDL should have an http endpoint
+ * instead of an https endpoint.
+ */
+ public static final String HTTP_PARAMETER_VALUE = "http"; //$NON-NLS-1$
+
+ /*
+ * Static contant representing the standard http protocol.
+ */
+ public static final String HTTP = "http"; //$NON-NLS-1$
+
+ /**
+ * Static contant representing the secure http protocol.
+ */
+ public static final String HTTPS = "https"; //$NON-NLS-1$
+
+ /**
+ * Default content type for the VDBResourceServlet
+ */
+ public static final String DEFAULT_CONTENT_TYPE = "text/html"; //$NON-NLS-1$
+
+ /**
+ * XML content type for the VDBResourceServlet
+ */
+ public static final String XML_CONTENT_TYPE = "text/xml"; //$NON-NLS-1$
+
+ /**
+ * WSDL URL Generator keys
+ */
+ public static final String MMSERVER_HOST_PORT_KEY = "MMServerHostAndPort";
//$NON-NLS-1$
+
+ public static final String TARGET_HOST_KEY = "TargetHost"; //$NON-NLS-1$
+
+ public static final String TARGET_PORT_KEY = "TargetPort"; //$NON-NLS-1$
+
+ public static final String SERVLET_PATH = "/servlet/ArtifactDocumentService";
//$NON-NLS-1$
+
+ public static final String SQLQUERYWEBSERVICE_WSDL_PATH =
"/services/SqlQueryWebService?wsdl"; //$NON-NLS-1$
+
+ public static final String GENERATED_WSDL_NAME = "MetaMatrixDataServices";
//$NON-NLS-1$
+
+ public static final String GENERATED_WSDL_FILENAME = GENERATED_WSDL_NAME +
".wsdl"; //$NON-NLS-1$
+
+ public static final String COLON = ":"; //$NON-NLS-1$
+
+ public static final String SLASH = "/"; //$NON-NLS-1$
+
+ public static final String DOUBLE_SLASH = "//"; //$NON-NLS-1$
+
+ public static final String AMP = "&"; //$NON-NLS-1$
+
+ public static final String QUESTION_MARK = "?"; //$NON-NLS-1$
+
+ public static final String EQUALS = "="; //$NON-NLS-1$
+
+ public static final String COMMA = ","; //$NON-NLS-1$
+
+ private static final String SQLQUERYWEBSERVICE_URL_FORMAT =
"{0}://{1}:{2}/{3}"; //$NON-NLS-1$
+
+ /*
+ * this default value is based on Tomcat's default value in its server.xml file.
This value can be overridden by setting the
+ * com.metamatrix.webservice.dataservice.httpsport System property for the VM that this
servlet is running in.
+ */
+ private static final String DEFAULT_HTTPS_PORT = "8443"; //$NON-NLS-1$
+
+ private static final String DEFAULT_HTTP_PORT = "8080"; //$NON-NLS-1$
+
+ private static final String HTTPS_PORT_PROPERTY_KEY =
"com.metamatrix.webservice.dataservice.httpsport"; //$NON-NLS-1$
+
+ private static final String HTTP_PORT_PROPERTY_KEY =
"com.metamatrix.webservice.dataservice.httpport"; //$NON-NLS-1$
+
+ /**
+ * Returns the formatted url from the supplied info
+ *
+ * @param scheme the server scheme
+ * @param host the server host name
+ * @param port the server port
+ * @param appContext the context of this application to use in the WSDL url
+ * @param serverURLs the list of server url info, first url is full url including
protocol. Subsequent items are just the
+ * host:port strings.
+ * @param vdbName the vdb name
+ * @param vdbVersion the vdb version number
+ */
+ public static String formatURL( String scheme,
+ String host,
+ String port,
+ String appContext,
+ List serverURLs,
+ String vdbName,
+ String vdbVersion ) {
+
+ StringBuffer result = new StringBuffer();
+ try {
+ boolean hasPort = true;
+ boolean hasVDBVersion = true;
+
+ if (port == null || port.length() == 0) {
+ hasPort = false;
+ }
+
+ if (vdbVersion == null || vdbVersion.trim().length() == 0) {
+ hasVDBVersion = false;
+ }
+
+ result.append(scheme).append(COLON).append(DOUBLE_SLASH).append(host);
+
+ if (hasPort) {
+ result.append(COLON).append(port);
+ }
+
+ result.append(appContext).append(SERVLET_PATH).append(SLASH).append(GENERATED_WSDL_FILENAME);
+ result.append(QUESTION_MARK).append(SERVER_URL_KEY).append(EQUALS);
+ // Append comma-delimited server urls
+ Iterator iter = serverURLs.iterator();
+ while (iter.hasNext()) {
+ String serverURL = (String)iter.next();
+ result.append(serverURL);
+ // If there is another url coming, add an encoded comma
+ if (iter.hasNext()) {
+ result.append(URLEncoder.encode(COMMA, "UTF-8")); //$NON-NLS-1$
+ }
+ }
+ result.append(AMP).append(VDB_NAME_KEY).append(EQUALS).append(vdbName);
+ if (hasVDBVersion) {
+ result.append(AMP).append(VDB_VERSION_KEY).append(EQUALS).append(vdbVersion);
+ }
+
+ } catch (UnsupportedEncodingException err) {
+ // ignore
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Returns the formatted wsdl url for the SqlQueryWebService
+ *
+ * @param server - server name
+ * @param appContext the context of this application to use in the WSDL url
+ * @param secure - secure ssl (true) or non-secure (false)
+ * @return wsdlUrl - String
+ * @since 4.3
+ */
+ public static String getSqlQueryWebServiceUrl( final String server,
+ String appContext,
+ final boolean secure ) {
+
+ appContext=appContext.replace("/",""); //$NON-NLS-1$ //$NON-NLS-2$
+ return MessageFormat.format(SQLQUERYWEBSERVICE_URL_FORMAT, new Object[] {secure ? HTTPS
: HTTP, server,
+ secure ? getHttpsPort() : getHttpPort(),
appContext+SQLQUERYWEBSERVICE_WSDL_PATH});
+ }
+
+ public static final String getHttpsPort() {
+ return System.getProperty(HTTPS_PORT_PROPERTY_KEY, DEFAULT_HTTPS_PORT);
+ }
+
+ public static final String getHttpPort() {
+ return System.getProperty(HTTP_PORT_PROPERTY_KEY, DEFAULT_HTTP_PORT);
+ }
+}
Property changes on:
trunk/soap/src/main/java/com/metamatrix/soap/util/WSDLServletUtil.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified:
trunk/soap/src/test/java/com/metamatrix/soap/handler/TestActionUpdateHandler.java
===================================================================
---
trunk/soap/src/test/java/com/metamatrix/soap/handler/TestActionUpdateHandler.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/soap/src/test/java/com/metamatrix/soap/handler/TestActionUpdateHandler.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -29,7 +29,7 @@
import org.apache.axis2.context.MessageContext;
-import com.metamatrix.common.util.WSDLServletUtil;
+import com.metamatrix.soap.util.WSDLServletUtil;
public class TestActionUpdateHandler extends TestCase{
Modified:
trunk/soap/src/test/java/com/metamatrix/soap/service/TestDataServiceWebServiceImpl.java
===================================================================
---
trunk/soap/src/test/java/com/metamatrix/soap/service/TestDataServiceWebServiceImpl.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/soap/src/test/java/com/metamatrix/soap/service/TestDataServiceWebServiceImpl.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -28,7 +28,7 @@
import org.apache.axis2.AxisFault;
-import com.metamatrix.common.util.WSDLServletUtil;
+import com.metamatrix.soap.util.WSDLServletUtil;
/**
*
Modified:
trunk/soap/src/test/java/com/metamatrix/soap/servlet/TestMMGetVDBResourceServlet.java
===================================================================
---
trunk/soap/src/test/java/com/metamatrix/soap/servlet/TestMMGetVDBResourceServlet.java 2009-05-07
21:28:59 UTC (rev 884)
+++
trunk/soap/src/test/java/com/metamatrix/soap/servlet/TestMMGetVDBResourceServlet.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -25,7 +25,7 @@
import java.util.Map;
import java.util.TreeMap;
-import com.metamatrix.common.util.WSDLServletUtil;
+import com.metamatrix.soap.util.WSDLServletUtil;
import junit.framework.TestCase;
Copied: trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java (from
rev 872,
trunk/common-core/src/test/java/com/metamatrix/common/util/TestWSDLServletUtil.java)
===================================================================
--- trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java
(rev 0)
+++ trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java 2009-05-07
21:35:26 UTC (rev 885)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.soap.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.metamatrix.soap.util.WSDLServletUtil;
+
+import junit.framework.TestCase;
+
+/**
+ */
+public class TestWSDLServletUtil extends TestCase {
+
+ public static String HTTP = "http"; //$NON-NLS-1$
+ public static String HTTPS = "https"; //$NON-NLS-1$
+ public static String DEFAULT_APP_CONTEXT = "/metamatrix-soap"; //$NON-NLS-1$
+ public static String OTHER_APP_CONTEXT = "/metamatrix-soapiness";
//$NON-NLS-1$
+
+ public TestWSDLServletUtil(String name) {
+ super(name);
+ }
+
+ public void testGetMMSAPIUrlAllNullServerNameSecure() {
+ String url = WSDLServletUtil.getSqlQueryWebServiceUrl(null, DEFAULT_APP_CONTEXT,
true);
+
assertEquals("https://null:8443/metamatrix-soap/services/SqlQueryWebService?wsdl",
url); //$NON-NLS-1$
+ }
+
+ public void testGetMMSAPIUrlAllNullServerNameNonSecure() {
+ String url = WSDLServletUtil.getSqlQueryWebServiceUrl(null, DEFAULT_APP_CONTEXT,
false);
+
assertEquals("http://null:8080/metamatrix-soap/services/SqlQueryWebService?wsdl",
url); //$NON-NLS-1$
+ }
+
+ public void testGetMMSAPIUrlValidParametersSecure() {
+ String url = WSDLServletUtil.getSqlQueryWebServiceUrl("slntmm01",
DEFAULT_APP_CONTEXT, true); //$NON-NLS-1$
+
assertEquals("https://slntmm01:8443/metamatrix-soap/services/SqlQueryWebService?wsdl",
url); //$NON-NLS-1$
+ }
+
+ public void testGetMMSAPIUrlValidParametersNonSecure() {
+ String url = WSDLServletUtil.getSqlQueryWebServiceUrl("slntmm01",
OTHER_APP_CONTEXT,false); //$NON-NLS-1$
+
assertEquals("http://slntmm01:8080/metamatrix-soapiness/services/SqlQueryWebService?wsdl",
url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersNonSecure() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mm://chicago:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTP,"chicago","8080",
DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
assertEquals("http://chicago:8080/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mm://chicago:31000&VDBName=testVDB&VDBVersion=1",
url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersSecure() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
+ String url =
WSDLServletUtil.formatURL(HTTPS,"chicago","8443", DEFAULT_APP_CONTEXT,
serverURLs,"testVDB","1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+
assertEquals("https://chicago:8443/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mms://chicago:31000&VDBName=testVDB&VDBVersion=1",
url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersSecureNoPort() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTPS,"chicago",null,
DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+
assertEquals("https://chicago/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mms://chicago:31000&VDBName=testVDB&VDBVersion=1",
url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersSecureNoPortNoVdbVersion() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTPS,"chicago",null,
OTHER_APP_CONTEXT, serverURLs,"testVDB",null); //$NON-NLS-1$ //$NON-NLS-2$
+
assertEquals("https://chicago/metamatrix-soapiness/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mms://chicago:31000&VDBName=testVDB",
url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlValidParametersSecureNoVdbVersion() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mms://chicago:31000"); //$NON-NLS-1$
+ String url =
WSDLServletUtil.formatURL(HTTPS,"chicago","8443", DEFAULT_APP_CONTEXT,
serverURLs,"testVDB",""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
+
assertEquals("https://chicago:8443/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mms://chicago:31000&VDBName=testVDB",
url); //$NON-NLS-1$
+ }
+
+ public void testFormatUrlMultipleServers() {
+ List serverURLs = new ArrayList();
+ serverURLs.add("mm://chicago:31000"); //$NON-NLS-1$
+ serverURLs.add("boston:31000"); //$NON-NLS-1$
+ String url = WSDLServletUtil.formatURL(HTTP,"chicago","8080",
DEFAULT_APP_CONTEXT, serverURLs,"testVDB","1"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
assertEquals("http://chicago:8080/metamatrix-soap/servlet/ArtifactDocumentService/MetaMatrixDataServices.wsdl?ServerURL=mm://chicago:31000%2Cboston:31000&VDBName=testVDB&VDBVersion=1",
url); //$NON-NLS-1$
+ }
+
+}
Property changes on:
trunk/soap/src/test/java/com/metamatrix/soap/util/TestWSDLServletUtil.java
___________________________________________________________________
Name: svn:mergeinfo
+