Author: tejones
Date: 2010-02-19 11:49:44 -0500 (Fri, 19 Feb 2010)
New Revision: 1853
Removed:
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnection.java
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnectionFactory.java
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeInvalidConnectionFactory.java
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/TestConnectionPool.java
Log:
TEIID-807: Cleaned up legacy code and added VDB deployment/un-deployment. Also added
operation execution framework.
Deleted: branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnection.java
===================================================================
---
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnection.java 2010-02-19
16:49:31 UTC (rev 1852)
+++
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnection.java 2010-02-19
16:49:44 UTC (rev 1853)
@@ -1,243 +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.rhq.comm.impl;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.teiid.rhq.comm.Component;
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionException;
-import org.teiid.rhq.comm.ConnectionPool;
-import org.teiid.rhq.comm.ExecutedResult;
-
-
-/**
- * @since 6.2
- */
-public class FakeConnection implements Connection{
-
- public static int NUM_CONNECTORS = 3;
- public static int NUM_VMS = 2;
- public static int NUM_HOSTS = 1;
-
- private static final String HOST_ID = "Host_id_1"; //$NON-NLS-1$
-
- private String installDir = null;
- private ConnectionPool pool;
- private Properties envProps = null;
-
- public FakeConnection(ConnectionPool pool, Properties env) {
- this.pool = pool;
- this.envProps = env;
-
- }
-
-
-
- @Override
- public Collection<Component> discoverComponents(String componentType,
- String identifier) throws ConnectionException {
- // TODO Auto-generated method stub
- return null;
- }
-
-
-
- @Override
- public void executeOperation(ExecutedResult result, Map valueMap)
- throws ConnectionException {
- // TODO Auto-generated method stub
-
- }
-
-
-
- @Override
- public String getKey() throws Exception {
- // TODO Auto-generated method stub
- return "fakekey";
- }
-
-
-
- @Override
- public Object getMetric(String componentType, String identifier,
- String metric, Map valueMap) throws ConnectionException {
- // TODO Auto-generated method stub
- return null;
- }
-
-
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#isValid()
- * @since 6.2
- */
- public boolean isValid() {
- return true;
- }
-
- /**
- * @throws Exception
- * @see com.metamatrix.rhq.comm.Connection#close()
- * @since 6.2
- */
- public void close() {
- try {
- pool.close(this);
- } catch (Exception err) {
- throw new RuntimeException(err);
-
- }
- }
-
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#getConnectors(java.lang.String)
- * @since 6.2
- */
- public Collection<Component> getConnectors(String vmname) throws
ConnectionException {
- Collection<Component> vms = getVMs();
- Collection<Component> cs = new ArrayList(5);
- for (Iterator vmIt=vms.iterator(); vmIt.hasNext();) {
- Component vm = (Component) vmIt.next();
- for (int i = 0; i < NUM_VMS; i++) {
- ComponentImpl c = new ComponentImpl();
- c.setSystemKey(this.installDir);
- c.setIdentifier(vm.getIdentifier() + "|VM_id_" + i);
//$NON-NLS-1$
- c.setName("VM_id_" + i); //$NON-NLS-1$
- cs.add(c);
- }
- }
-
- return cs;
- }
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#getEnvironment()
- * @since 6.2
- */
- public Properties getEnvironment() throws Exception {
- return this.envProps;
- }
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#getHost()
- * @since 6.2
- */
- public Component getHost() throws ConnectionException {
- ComponentImpl c = new ComponentImpl();
- c.setSystemKey(this.installDir);
- c.setIdentifier(HOST_ID);
- c.setName(HOST_ID );
- c.setPort("1"); //$NON-NLS-1$
- return c;
- }
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#getInstallationDirectory()
- * @since 6.2
- */
- public String getInstallationDirectory() throws Exception {
- return installDir;
- }
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#getMetric(java.lang.String,
java.lang.String, java.util.Map)
- * @since 6.2
- */
- public Object getMetric(String componentType,
- String metric,
- Map valueMap) throws ConnectionException {
- return null;
- }
-
-
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#getProperties(java.lang.String,
java.lang.String)
- * @since 6.2
- */
- public Properties getProperties(String resourceType,
- String identifier) throws ConnectionException {
- return null;
- }
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#getProperty(java.lang.String,
java.lang.String)
- * @since 6.2
- */
- public String getProperty(String identifier,
- String property) throws ConnectionException {
- return this.envProps.getProperty(property);
- }
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#getVMs()
- * @since 6.2
- */
- public Collection<Component> getVMs() throws ConnectionException {
-
-
- Component host = getHost();
- Collection cs = new ArrayList(5);
- for (int i = 0; i < NUM_VMS; i++) {
- ComponentImpl c = new ComponentImpl();
- c.setSystemKey(this.installDir);
- c.setIdentifier(host.getIdentifier() + "|VM_id_" + i);
//$NON-NLS-1$
- c.setName("VM_id_" + i); //$NON-NLS-1$
- c.setPort(String.valueOf(i));
- cs.add(c);
- }
-
- return cs;
-
- }
-
- public Collection<Component> getVDBs(List fieldNameList) throws
ConnectionException {
- return Collections.EMPTY_LIST;
- }
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#isAlive()
- * @since 6.2
- */
- public boolean isAlive() {
- return true;
- }
-
- /**
- * @see com.metamatrix.rhq.comm.Connection#isAvailable(java.lang.String,
java.lang.String)
- * @since 6.2
- */
- public Boolean isAvailable(String componentType,
- String identifier) throws ConnectionException {
- return true;
- }
-
-}
Deleted:
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnectionFactory.java
===================================================================
---
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnectionFactory.java 2010-02-19
16:49:31 UTC (rev 1852)
+++
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeConnectionFactory.java 2010-02-19
16:49:44 UTC (rev 1853)
@@ -1,80 +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.rhq.comm.impl;
-
-
-import java.util.Properties;
-
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionException;
-import org.teiid.rhq.comm.ConnectionFactory;
-import org.teiid.rhq.comm.ConnectionPool;
-
-
-
-
-public class FakeConnectionFactory implements
- ConnectionFactory {
-
- static boolean createdfactory = false;
- private static Properties connEnv;
- private ConnectionPool pool;
-
- public Connection createConnection(){
-
- return new FakeConnection(pool, connEnv);
-
- }
-
-
-
-
- @Override
- public String getURL() {
- // TODO Auto-generated method stub
- return null;
- }
-
-
-
-
- @Override
- public void initialize(Properties env, ConnectionPool connectionPool)
- throws ConnectionException {
- connEnv = env;
- this.pool = connectionPool;
- createdfactory = true;
-
- }
-
-
- public void closeConnection(Connection connection) {
-
- }
-
-
- public String getProperty(String key) {
- return connEnv.getProperty(key);
- }
-
-
-}
Deleted:
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeInvalidConnectionFactory.java
===================================================================
---
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeInvalidConnectionFactory.java 2010-02-19
16:49:31 UTC (rev 1852)
+++
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/FakeInvalidConnectionFactory.java 2010-02-19
16:49:44 UTC (rev 1853)
@@ -1,81 +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.rhq.comm.impl;
-
-
-import java.util.Properties;
-
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionException;
-import org.teiid.rhq.comm.ConnectionFactory;
-import org.teiid.rhq.comm.ConnectionPool;
-
-
-
-public class FakeInvalidConnectionFactory implements
- ConnectionFactory {
-
- static boolean createdfactory = false;
- private static Properties connEnv;
- private ConnectionPool pool;
-
- public Connection createConnection(){
-
- Connection result = new InvalidConnectionImpl("INVALIDKEY", connEnv,
pool);
-
-
- return result;
- }
-
-
-
-
- @Override
- public String getURL() {
- // TODO Auto-generated method stub
- return null;
- }
-
-
-
-
- @Override
- public void initialize(Properties env, ConnectionPool connectionPool)
- throws ConnectionException {
- connEnv = env;
- this.pool = connectionPool;
- createdfactory = true;
-
- }
-
-
- public void closeConnection(Connection connection) {
-
- }
-
-
- public String getProperty(String key) {
- return connEnv.getProperty(key);
- }
-
-
-}
Deleted:
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/TestConnectionPool.java
===================================================================
---
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/TestConnectionPool.java 2010-02-19
16:49:31 UTC (rev 1852)
+++
branches/JCA/console/src/test/java/org/teiid/rhq/comm/impl/TestConnectionPool.java 2010-02-19
16:49:44 UTC (rev 1853)
@@ -1,376 +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.rhq.comm.impl;
-
-import java.util.Properties;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.teiid.rhq.comm.Connection;
-import org.teiid.rhq.comm.ConnectionConstants;
-import org.teiid.rhq.comm.ConnectionPool;
-//import org.teiid.rhq.embedded.pool.ConnectionPoolImpl;
-
-import org.teiid.rhq.enterprise.pool.ConnectionPoolImpl;
-
-
-
-
-/**
- * @since 4.3
- */
-public class TestConnectionPool extends TestCase {
- static {
- //
System.setProperty(SingletonConnectionManager.INSTALL_SERVER_PROP,StartingEnvironmentConstants.SINGLE_SYSTEM_PARM);
-
- // reset the conn mager for the next test case class
-
- }
-
- private boolean failure = false;
- int count;
-
- /**
- * This suite of all tests could be defined in another class but it seems easier to
- * maintain it here.
- */
- public static Test suite() {
-
- TestSuite suite = new TestSuite("TestConnectionPool"); //$NON-NLS-1$
- suite.addTestSuite(TestConnectionPool.class);
- return suite;
- }
-
-
- // ################################## MAIN ################################
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- /**
- * @since 1.0
- */
-// public static void main(final String[] arguments) {
-// try {
-//
-// TestConnectionPool test = new TestConnectionPool();
-// test.runTest();
-//
-//
-// }catch (Exception e) {
-// e.printStackTrace();
-// }
-// }
-
-// public void runTest() throws Exception {
-// testSimple();
-// testSecond();
-// testThreading();
-// }
-
- public void testSimple() throws Exception {
- log("Start simpleTest...");
- failure = false;
-
- Properties props = new Properties();
- props.setProperty(ConnectionPool.CONNECTION_FACTORY,
"org.teiid.rhq.comm.impl.FakeConnectionFactory");
-
- ConnectionPool pool = new ConnectionPoolImpl();
- pool.initialize(props, this.getClass().getClassLoader());
-
- if (!FakeConnectionFactory.createdfactory) {
- logError("Didn't use the fake factory");
- }
-
- Connection conn = pool.getConnection();
-
- int cnt = pool.getAvailableConnectionCount();
- if (cnt != 0) {
- logError("Available count should have been 0, but was " + cnt);
- }
-
-
- cnt = pool.getConnectionsInUseCount();
- if (cnt != 1) {
- logError("Connections in use should have been 1, but was " + cnt);
- }
-
- pool.close(conn);
-
- cnt = pool.getConnectionsInUseCount();
- if (cnt != 0) {
- logError("Connections in use should have been 0 after checkin, but was
" + cnt);
- }
-
- cnt = pool.getAvailableConnectionCount();
- if (cnt != 1) {
- logError("Available count should have been 1 after checking, but was
" + cnt);
- }
-
- pool.shutdown();
- log("Was simpleTest a success " + !failure );
- }
-
- public void testSecond() throws Exception {
- log("Start secondTest...");
- failure = false;
- Properties props = new Properties();
- props.setProperty(ConnectionPool.CONNECTION_FACTORY,
"org.teiid.rhq.comm.impl.FakeConnectionFactory");
-
- ConnectionPool pool = new ConnectionPoolImpl();
- pool.initialize( props, this.getClass().getClassLoader());
-
- if (!FakeConnectionFactory.createdfactory) {
- logError("Didn't use the fake factory");
- }
-
- Connection conn = pool.getConnection();
- Connection conn2 = pool.getConnection();
- Connection conn3 = pool.getConnection();
-
- validateAvailCnt(pool, 0);
-
- validateInUseCnt(pool, 3);
-
-
- pool.close(conn);
-
- validateAvailCnt(pool, 1);
-
- validateInUseCnt(pool, 2);
-
-
- Connection conn4 = pool.getConnection();
- Connection conn5 = pool.getConnection();
-
- validateAvailCnt(pool, 0);
-
- validateInUseCnt(pool, 4);
-
- pool.close(conn5);
- pool.close(conn3);
- pool.close(conn2);
- pool.close(conn4);
-
- validateAvailCnt(pool, 4);
-
- validateInUseCnt(pool, 0);
-
- pool.shutdown();
- log("Was secondTest a success " + !failure );
- }
-
- private void validateInUseCnt(ConnectionPool pool, int cnt) {
-
-// int incnt = pool.getConnectionsInUseCount();
-// if (incnt != cnt) {
-// logError("Connections in use should have been " + cnt + " ,
but was " + incnt);
-// }
- }
-
- private void validateAvailCnt(ConnectionPool pool, int cnt) {
-
-// int incnt = pool.getAvailableConnectionCount();
-// if (incnt != cnt) {
-// logError("Available count should have been " + cnt + " , but
was " + incnt);
-// }
- }
-
- public void testThreading() throws Exception {
- failure = false;
- log("Start threadingTest...");
-
- Properties props = new Properties();
- props.setProperty(ConnectionPool.CONNECTION_FACTORY,
"org.teiid.rhq.comm.impl.FakeConnectionFactory");
- props.setProperty(ConnectionConstants.PASSWORD, "PW");
- props.setProperty(ConnectionConstants.USERNAME, "USERNAME");
-
- ConnectionPool pool = new ConnectionPoolImpl();
- pool.initialize( props, this.getClass().getClassLoader());
-
-
- int threadCnt = 10;
-// int max_size = 1;
- // int expectedNumErrors = threadCnt - max_size;
-
- TimeOutThread[] ts = new TimeOutThread[threadCnt];
-
- for (count = 0; count < threadCnt; count++) {
- ts[count] = new TimeOutThread(pool, 10, count);
- }
-
- for(int k = 0; k < threadCnt; k++){
- ts[k].start();
- }
-
- try {
- for(int k = 0; k < threadCnt; k++){
- ts[k].join();
- }
- } catch (InterruptedException e) {
- }
-
- for(int k = 0; k < threadCnt; k++){
- if (ts[k].hasException()) {
- Exception e = ts[k].getException();
-
- logError("Exception " + e.getMessage());
-
-
- }
- // which thread
- int pc = ts[k].getProcessCnt();
-
- // number of connections suppose to process per thread
- int ptc = ts[k].getPerThreadCnt();
-
- // the number of connection actually processed
- int mx = ts[k].getMaxProcessedCnt();
-
- // the end count of the connection left after close is suppose to be called
- int ct = ts[k].getConnectionCount();
- if (ct != 0) {
- logError("Thread " + pc + " did have the connections go
back down to zero");
- }
- if (ptc != mx) {
- logError("PerThreadCnt " + ptc + ", but only successfully
processed " + mx);
- } else {
- log("Process " + pc + " for thread # " + k);
- }
-
-
- }
-
- log("Was threadingTest a success " + !failure );
-
-
- }
-
-
-
- private void logError(String msg) {
- failure = true;
- System.out.println(msg);
- }
-
- private void log(String msg) {
- System.out.println(msg);
- }
-
- protected class TimeOutThread extends BaseThread{
- private ConnectionPool pool;
- private int connCnt = 0;
- private int processCnt = 0;
- private int maxCnt = 0;
-
-
- public TimeOutThread(ConnectionPool connpool, int connections, int processcnt) {
- super(connections);
- this.pool = connpool;
- this.processCnt = processcnt;
-
-
- }
- public int getProcessCnt() {
- return processCnt;
- }
-
- public int getMaxProcessedCnt() {
- return maxCnt;
- }
- public int getConnectionCount() {
- return this.connCnt;
- }
-
- public void run(){
- // DO NOT call resource.close(), all the resources should remain
- // checkedout to cause the next resource request to timeout.
-
-
- for (int i=0; i < perThreadCnt; i++ ) {
- Connection conn = null;
- try {
- conn = pool.getConnection();
- ++connCnt;
- ++maxCnt;
-
- yield();
-// Properties psrops =conn.
-// if (psrops == null || psrops.isEmpty()) {
-// setException(new Exception("Null Environment"));
-// }
-// if (conn.getProperty(ConnectionConstants.USERNAME) == null) {
-// setException(new Exception("No UserName"));
-// }
-// if (psrops.size() < 3) {
-// setException(new Exception("NOt Enough Properties"));
-// System.out.println(psrops);
-// }
-
- } catch (Exception toe) {
- setException(toe);
-
- }
-
- // yield to the other thread to checkout instance, which should timeout
- try {
- pool.close(conn);
- --connCnt;
- } catch (Exception err) {
- setException(err);
- }
- }
- }
- }
-
- protected class BaseThread extends Thread{
- protected String objName = "Thread " + count; //$NON-NLS-1$
- protected int perThreadCnt = 1;
- private Exception t = null;
-
-
- public BaseThread(int iterationCnt) {
- perThreadCnt = iterationCnt;
- }
-
- public int getPerThreadCnt() {
- return perThreadCnt;
- }
-
- public Exception getException() {
- return t;
- }
-
- public void setException(Exception te) {
- t = te;
- }
-
- public boolean hasException() {
- return (t==null ? false : true);
- }
-
- }
-
-}