Author: shawkins
Date: 2010-07-15 12:22:12 -0400 (Thu, 15 Jul 2010)
New Revision: 2350
Removed:
trunk/common-core/src/main/java/org/teiid/core/util/FileUtil.java
trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtil.java
Modified:
trunk/api/src/main/java/org/teiid/logging/CommandLogMessage.java
trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtils.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
Log:
TEIID-1151 fix for datatiertuplesource, removing fileutil, and fixing the date formatting
in the command log message
Modified: trunk/api/src/main/java/org/teiid/logging/CommandLogMessage.java
===================================================================
--- trunk/api/src/main/java/org/teiid/logging/CommandLogMessage.java 2010-07-15 01:21:21
UTC (rev 2349)
+++ trunk/api/src/main/java/org/teiid/logging/CommandLogMessage.java 2010-07-15 16:22:12
UTC (rev 2350)
@@ -22,8 +22,7 @@
package org.teiid.logging;
-import java.text.DateFormat;
-import java.util.Date;
+import java.sql.Timestamp;
import org.teiid.translator.ExecutionContext;
@@ -138,20 +137,17 @@
public String toString() {
if (!source && event == Event.NEW) {
- return "\tSTART USER COMMAND:\tstartTime=" + getTimestampString(new
Date(timestamp)) + "\trequestID=" + requestID + "\ttxID=" +
transactionID + "\tsessionID=" + sessionID + "\tapplicationName=" +
applicationName + "\tprincipal=" + principal + "\tvdbName=" + vdbName
+ "\tvdbVersion=" + vdbVersion + "\tsql=" + sql; //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
//$NON-NLS-8$ //$NON-NLS-9$
+ return "\tSTART USER COMMAND:\tstartTime=" + new Timestamp(timestamp) +
"\trequestID=" + requestID + "\ttxID=" + transactionID +
"\tsessionID=" + sessionID + "\tapplicationName=" + applicationName +
"\tprincipal=" + principal + "\tvdbName=" + vdbName +
"\tvdbVersion=" + vdbVersion + "\tsql=" + sql; //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
//$NON-NLS-8$ //$NON-NLS-9$
}
if (!source) {
- return "\t"+ event +" USER COMMAND:\tendTime=" +
getTimestampString(new Date(timestamp)) + "\trequestID=" + requestID +
"\ttxID=" + transactionID + "\tsessionID=" + sessionID +
"\tprincipal=" + principal + "\tvdbName=" + vdbName +
"\tvdbVersion=" + vdbVersion + "\tfinalRowCount=" + rowCount;
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$
//$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
+ return "\t"+ event +" USER COMMAND:\tendTime=" + new
Timestamp(timestamp) + "\trequestID=" + requestID + "\ttxID=" +
transactionID + "\tsessionID=" + sessionID + "\tprincipal=" +
principal + "\tvdbName=" + vdbName + "\tvdbVersion=" + vdbVersion +
"\tfinalRowCount=" + rowCount; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
}
if (event == Event.NEW) {
- return "\tSTART DATA SRC COMMAND:\tstartTime=" + getTimestampString(new
Date(timestamp)) + "\trequestID=" + requestID + "\tsourceCommandID="+
sourceCommandID + "\ttxID=" + transactionID + "\tmodelName="+
modelName + "\tconnectorBindingName=" + connectorBindingName +
"\tsessionID=" + sessionID + "\tprincipal=" + principal +
"\tsql=" + sql; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
+ return "\tSTART DATA SRC COMMAND:\tstartTime=" + new Timestamp(timestamp)
+ "\trequestID=" + requestID + "\tsourceCommandID="+ sourceCommandID +
"\ttxID=" + transactionID + "\tmodelName="+ modelName +
"\tconnectorBindingName=" + connectorBindingName + "\tsessionID=" +
sessionID + "\tprincipal=" + principal + "\tsql=" + sql;
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$
//$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
}
- return "\t"+ event +" SRC COMMAND:\tendTime=" +
getTimestampString(new Date(timestamp)) + "\trequestID=" + requestID +
"\tsourceCommandID="+ sourceCommandID + "\ttxID=" + transactionID +
"\tmodelName="+ modelName + "\tconnectorBindingName=" +
connectorBindingName + "\tsessionID=" + sessionID + "\tprincipal=" +
principal + "\tfinalRowCount=" + rowCount; //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
//$NON-NLS-9$ //$NON-NLS-10$
+ return "\t"+ event +" SRC COMMAND:\tendTime=" + new
Timestamp(timestamp) + "\trequestID=" + requestID +
"\tsourceCommandID="+ sourceCommandID + "\ttxID=" + transactionID +
"\tmodelName="+ modelName + "\tconnectorBindingName=" +
connectorBindingName + "\tsessionID=" + sessionID + "\tprincipal=" +
principal + "\tfinalRowCount=" + rowCount; //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
//$NON-NLS-9$ //$NON-NLS-10$
}
- private String getTimestampString(Date date) {
- return DateFormat.getDateInstance().format(date);
- }
public long getTimestamp() {
return timestamp;
}
Deleted: trunk/common-core/src/main/java/org/teiid/core/util/FileUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/FileUtil.java 2010-07-15 01:21:21
UTC (rev 2349)
+++ trunk/common-core/src/main/java/org/teiid/core/util/FileUtil.java 2010-07-15 16:22:12
UTC (rev 2350)
@@ -1,185 +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.core.util;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringWriter;
-
-import org.teiid.core.TeiidRuntimeException;
-
-
-/**
- * Utility class for dealing with files. Hides exception handling and file resource
management.
- */
-public class FileUtil {
- private File file;
-
- public FileUtil(String fileName) {
- this.file = new File(fileName);
- }
-
- public FileUtil(File file) {
- this.file = file;
- }
-
- private FileWriter getWriter(boolean append){
- try {
- return new FileWriter(this.file, append);
- } catch (IOException e) {
- throw new TeiidRuntimeException(e);
- }
- }
-
- public void append(String text) {
- FileWriter writer = null;
- try {
- try {
- writer = getWriter(true);
- writer.write(text);
- } finally {
- if (writer != null) {
- writer.close();
- }
- }
- } catch (IOException e) {
- throw new TeiidRuntimeException(e);
- }
- }
-
- public void write(String text) {
- delete();
- append(text);
- }
-
- public void delete() {
- this.file.delete();
- }
-
- public void writeBytes(byte[] bytes) {
- delete();
- FileOutputStream stream = null;
- try {
- try {
- stream = new FileOutputStream(this.file);
- stream.write(bytes);
- stream.flush();
- } finally {
- if (stream != null) {
- stream.close();
- }
- }
- } catch (FileNotFoundException e) {
- throw new TeiidRuntimeException(e);
- } catch (IOException e) {
- throw new TeiidRuntimeException(e);
- }
- }
-
- public String read() {
- try {
- return readSafe();
- } catch (FileNotFoundException e) {
- throw new TeiidRuntimeException(e);
- }
- }
-
- public String readSafe() throws FileNotFoundException {
- String result;
- FileReader reader = null;
- try {
- reader = new FileReader(this.file);
- result = read(reader);
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (Exception e) {
- }
- }
- }
-
- return result;
- }
-
- public static String read(Reader reader) {
- StringWriter writer = new StringWriter();
- BufferedReader bufferedReader = null;
- try {
- bufferedReader = new BufferedReader(reader);
- while (bufferedReader.ready()) {
- String line = bufferedReader.readLine();
- writer.write(line);
- writer.write(StringUtil.LINE_SEPARATOR);
- }
- } catch (IOException e) {
- throw new TeiidRuntimeException(e);
- } finally {
- if (bufferedReader != null) {
- try {
- bufferedReader.close();
- } catch (Exception e) {
- }
- }
- }
- return writer.toString();
- }
-
- public byte[] readBytes() {
- try {
- return readBytesSafe();
- } catch (FileNotFoundException e) {
- throw new TeiidRuntimeException(e);
- } catch (IOException e) {
- throw new TeiidRuntimeException(e);
- }
- }
-
- public byte[] readBytesSafe() throws FileNotFoundException, IOException {
- ByteArrayOutputStream result = new ByteArrayOutputStream();
- FileInputStream input = null;
- try {
- input = new FileInputStream(this.file);
- byte[] buffer = new byte[1024];
- int readCount = input.read(buffer);
- while (readCount > 0) {
- result.write(buffer, 0, readCount);
- readCount = input.read(buffer);
- }
- return result.toByteArray();
- } finally {
- if (input != null) {
- input.close();
- }
- }
-
- }
-}
Deleted: trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtil.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtil.java 2010-07-15
01:21:21 UTC (rev 2349)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtil.java 2010-07-15
16:22:12 UTC (rev 2350)
@@ -1,49 +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.core.util;
-
-import java.io.File;
-
-import org.teiid.core.util.FileUtil;
-import org.teiid.core.util.StringUtil;
-
-import junit.framework.TestCase;
-
-public class TestFileUtil extends TestCase {
-
- public TestFileUtil(String name) {
- super(name);
- }
-
- public void testWriteBytes() {
- String text = "This is some sample text."; //$NON-NLS-1$
- byte[] bytes = text.getBytes();
- String testFileName = UnitTestUtil.getTestDataPath() + File.separator+
"fakeFileWriteBytes"; //$NON-NLS-1$
- FileUtil testFile = new FileUtil(testFileName);
- testFile.delete();
- testFile.writeBytes(bytes);
- String result = testFile.read();
- assertEquals(text + StringUtil.LINE_SEPARATOR, result);
- testFile.delete();
- }
-}
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtils.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtils.java 2010-07-15
01:21:21 UTC (rev 2349)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtils.java 2010-07-15
16:22:12 UTC (rev 2350)
@@ -26,13 +26,11 @@
import java.io.FileInputStream;
import java.io.IOException;
-import org.teiid.core.TeiidException;
-import org.teiid.core.util.FileUtil;
-import org.teiid.core.util.FileUtils;
-
import junit.framework.TestCase;
+import org.teiid.core.TeiidException;
+
/**
* @since 4.0
*/
@@ -154,11 +152,11 @@
* @since 4.3
*/
public void testCopy() throws Exception {
- String contents1 = new FileUtil(FILE_NAME).read();
+ String contents1 = ObjectConverterUtil.convertFileToString(new File(FILE_NAME));
//positive case
FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, false);
- String contents2 = new FileUtil(TEMP_FILE_NAME).read();
+ String contents2 = ObjectConverterUtil.convertFileToString(new
File(TEMP_FILE_NAME));
assertEquals("Expected file contents to be the same", contents1,
contents2); //$NON-NLS-1$
assertTrue("Expected original file to still exist", new
File(FILE_NAME).exists()); //$NON-NLS-1$
@@ -172,7 +170,7 @@
//positive case: should succeed because we've specified to overwrite
FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, true);
- contents2 = new FileUtil(TEMP_FILE_NAME).read();
+ contents2 = ObjectConverterUtil.convertFileToString(new File(TEMP_FILE_NAME));
assertEquals("Expected file contents to be the same", contents1,
contents2); //$NON-NLS-1$
assertTrue("Expected original file to still exist", new
File(FILE_NAME).exists()); //$NON-NLS-1$
@@ -184,13 +182,13 @@
* @since 4.3
*/
public void testRename() throws Exception {
- String contents1 = new FileUtil(FILE_NAME).read();
+ String contents1 = ObjectConverterUtil.convertFileToString(new File(FILE_NAME));
//positive case
FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, true);
FileUtils.rename(TEMP_FILE_NAME, TEMP_FILE_NAME2, false);
- String contents2 = new FileUtil(TEMP_FILE_NAME2).read();
+ String contents2 = ObjectConverterUtil.convertFileToString(new
File(TEMP_FILE_NAME2));
assertEquals("Expected file contents to be the same", contents1,
contents2); //$NON-NLS-1$
assertFalse("Expected original file to not exist", new
File(TEMP_FILE_NAME).exists()); //$NON-NLS-1$
@@ -209,7 +207,7 @@
FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, true);
FileUtils.copy(FILE_NAME, TEMP_FILE_NAME2, true);
FileUtils.rename(TEMP_FILE_NAME, TEMP_FILE_NAME2, true);
- contents2 = new FileUtil(TEMP_FILE_NAME2).read();
+ contents2 = ObjectConverterUtil.convertFileToString(new File(TEMP_FILE_NAME2));
assertEquals("Expected file contents to be the same", contents1,
contents2); //$NON-NLS-1$
assertFalse("Expected original file to not exist", new
File(TEMP_FILE_NAME).exists()); //$NON-NLS-1$
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2010-07-15
01:21:21 UTC (rev 2349)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2010-07-15
16:22:12 UTC (rev 2350)
@@ -65,6 +65,7 @@
private boolean closed;
private volatile boolean canceled;
private boolean executed;
+ private volatile boolean done;
private volatile ResultsFuture<AtomicResultsMessage> futureResult;
private volatile boolean running;
@@ -146,7 +147,9 @@
AtomicResultsMessage results = null;
try {
results = currentResults.get();
- addWork();
+ if (results.getFinalRow() < 0) {
+ addWork();
+ }
} catch (InterruptedException e) {
throw new TeiidRuntimeException(e);
} catch (ExecutionException e) {
@@ -192,8 +195,7 @@
}
public boolean isDone() {
- AtomicResultsMessage results = this.arm;
- return results != null && results.getFinalRow() >= 0;
+ return done;
}
public boolean isRunning() {
@@ -280,6 +282,9 @@
workItem.addSourceFailureDetails(sourceFailure);
}
}
+ if (response.getFinalRow() >= 0) {
+ done = true;
+ }
}
public AtomicRequestMessage getAtomicRequestMessage() {
Modified:
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2010-07-15
01:21:21 UTC (rev 2349)
+++
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2010-07-15
16:22:12 UTC (rev 2350)
@@ -27,6 +27,7 @@
import org.junit.Test;
import org.mockito.Mockito;
import org.teiid.client.RequestMessage;
+import org.teiid.common.buffer.BlockedException;
import org.teiid.core.TeiidException;
import org.teiid.dqp.internal.datamgr.impl.ConnectorManagerRepository;
import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
@@ -34,8 +35,6 @@
import org.teiid.dqp.message.RequestID;
import org.teiid.dqp.service.AutoGenDataService;
import org.teiid.dqp.service.FakeBufferService;
-import org.teiid.dqp.service.TransactionContext;
-import org.teiid.dqp.service.TransactionContext.Scope;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.parser.QueryParser;
@@ -104,16 +103,21 @@
request = new AtomicRequestMessage(original, workContext, nodeId);
request.setCommand(command);
request.setConnectorName("FakeConnectorID"); //$NON-NLS-1$
- TransactionContext tc = new TransactionContext();
- tc.setTransactionType(Scope.GLOBAL);
- request.setTransactionContext(tc);
info = new DataTierTupleSource(request, workItem,
connectorManager.registerRequest(request), dtm);
}
@Test public void testDataTierTupleSource() throws Exception {
helpSetup(1);
- info.nextTuple();
+ for (int i = 0; i < 10;) {
+ try {
+ info.nextTuple();
+ i++;
+ } catch (BlockedException e) {
+ Thread.sleep(50);
+ }
+ }
assertNotNull(workItem.getConnectorRequest(request.getAtomicRequestID()));
+ assertNull(info.nextTuple());
info.closeSource();
assertNull(workItem.getConnectorRequest(request.getAtomicRequestID()));
}
@@ -139,7 +143,14 @@
@Test public void testNoRowsException() throws Exception {
helpSetup(3);
this.connectorManager.setRows(0);
- assertNull(info.nextTuple());
+ while (true) {
+ try {
+ assertNull(info.nextTuple());
+ break;
+ } catch (BlockedException e) {
+ Thread.sleep(50);
+ }
+ }
}
@Test public void testCodeTableResponseDataNotAvailable() throws Exception {
Modified:
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2010-07-15
01:21:21 UTC (rev 2349)
+++
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2010-07-15
16:22:12 UTC (rev 2350)
@@ -25,6 +25,7 @@
import static org.junit.Assert.*;
import java.io.File;
+import java.io.IOException;
import java.util.TimeZone;
import net.sf.saxon.trans.XPathException;
@@ -35,26 +36,25 @@
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.SQLXMLImpl;
import org.teiid.core.types.XMLType;
-import org.teiid.core.util.FileUtil;
+import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.query.unittest.TimestampUtil;
@SuppressWarnings("nls")
public class TestXMLSystemFunctions {
- public String getContentOfTestFile( final String testFilePath ) {
+ public String getContentOfTestFile( final String testFilePath ) throws IOException {
final File file = UnitTestUtil.getTestDataFile(testFilePath);
- final FileUtil util = new FileUtil(file.getAbsolutePath());
- return util.read();
+ return ObjectConverterUtil.convertFileToString(file);
}
- public String helpTestXpathValue(final String xmlFilePath, final String xpath, final
String expected) throws XPathException, TeiidProcessingException {
+ public String helpTestXpathValue(final String xmlFilePath, final String xpath, final
String expected) throws XPathException, TeiidProcessingException, IOException {
final String actual = helpGetNode(xmlFilePath,xpath);
assertEquals(expected,actual);
return actual;
}
- public String helpGetNode(final String xmlFilePath, final String xpath ) throws
XPathException, TeiidProcessingException {
+ public String helpGetNode(final String xmlFilePath, final String xpath ) throws
XPathException, TeiidProcessingException, IOException {
final String xmlContent = getContentOfTestFile(xmlFilePath);
return XMLSystemFunctions.xpathValue(xmlContent,xpath);
}