Skip to content

Commit

Permalink
TEIID-5572 correcting the file indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Dec 14, 2018
1 parent 5b25054 commit ec318ee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void execute() throws TranslatorException {

@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if(this.command.getProcedureName().equalsIgnoreCase(SAVEFILE) || this.command.getProcedureName().equalsIgnoreCase(DELETEFILE)){
if (files == null || index >= files.length) {
return null;
}
ArrayList<Object> result = new ArrayList<>(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@

import static org.junit.Assert.*;

import java.io.Closeable;
import java.io.File;
import java.sql.Blob;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import org.jboss.vfs.VFS;
import org.jboss.vfs.VirtualFile;
import org.junit.Test;
import org.mockito.Mockito;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.file.VirtualFileConnection;
import org.teiid.language.Argument;
import org.teiid.language.Argument.Direction;
import org.teiid.language.Call;
Expand Down Expand Up @@ -81,4 +86,32 @@ public class TestFileExecutionFactory {
assertEquals(1, count);
}


@Test public void testGetVirtualFiles() throws Exception {
FileExecutionFactory fef = new FileExecutionFactory();
MetadataFactory mf = new MetadataFactory("vdb", 1, "text", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
fef.getMetadata(mf, null);
Procedure p = mf.getSchema().getProcedure("getFiles");
VirtualFileConnection fc = Mockito.mock(VirtualFileConnection.class);
try (Closeable c = VFS.mountReal(new File(UnitTestUtil.getTestDataPath()), VFS.getChild("root"));) {
Mockito.stub(fc.getFiles("*.txt")).toReturn(new VirtualFile[] {VFS.getChild("root").getChild("file.txt")});
Call call = fef.getLanguageFactory().createCall("getFiles", Arrays.asList(new Argument(Direction.IN, new Literal("*.txt", TypeFacility.RUNTIME_TYPES.STRING), TypeFacility.RUNTIME_TYPES.STRING, null)), p);
ProcedureExecution pe = fef.createProcedureExecution(call, null, null, fc);
pe.execute();
int count = 0;
while (true) {
List<?> val = pe.next();
if (val == null) {
break;
}
assertTrue(val.get(0) instanceof Blob);
assertEquals(5, val.size());
assertTrue(val.get(3) instanceof Timestamp);
assertEquals(Long.valueOf(0), val.get(4));
count++;
}
assertEquals(1, count);
}
}

}

0 comments on commit ec318ee

Please sign in to comment.