/** Test that transactions do actually commit and that isInTransaction() works. */ public void testCommitTransactions() throws Exception { Address address1 = new Address(); address1.setAddress("Address 1"); Address address2 = new Address(); address2.setAddress("Address 2"); Query q = new Query(); QueryClass qcAddress = new QueryClass(Address.class); QueryField qf = new QueryField(qcAddress, "address"); ConstraintSet cs1 = new ConstraintSet(ConstraintOp.OR); cs1.addConstraint(new SimpleConstraint(qf, ConstraintOp.MATCHES, new QueryValue("Address%"))); q.addToSelect(qcAddress); q.addFrom(qcAddress); q.addToOrderBy(qf); q.setConstraint(cs1); try { writer.beginTransaction(); assertTrue(writer.isInTransaction()); writer.store(address1); writer.store(address2); // Should be nothing in OS until we commit Results res = realOs.execute(q); assertEquals(0, res.size()); // However, they should be in the WRITER. // TODO: These lines now fail, because we do not allow querying on writers with uncommitted // data. The writer should relax this restriction. res = writer.execute(q); assertEquals(2, res.size()); writer.commitTransaction(); assertFalse(writer.isInTransaction()); res = realOs.execute(q); assertEquals(2, res.size()); assertEquals(address1, (Address) ((ResultsRow) res.get(0)).get(0)); assertEquals(address2, (Address) ((ResultsRow) res.get(1)).get(0)); } finally { writer.delete(address1); writer.delete(address2); } }
public void testTranslation() throws Exception { ObjectStore os2 = new ObjectStoreTranslatingImpl( Model.getInstanceByName("testmodel"), ObjectStoreFactory.getObjectStore("os.unittest"), new CompanyTranslator()); Query q = new Query(); QueryClass qc = new QueryClass(InterMineObject.class); q.addToSelect(qc); q.addFrom(qc); Results res = os2.execute(q); assertEquals(2, res.size()); assertEquals("CompanyA", ((Bank) ((ResultsRow) res.get(0)).get(0)).getName()); assertEquals("CompanyB", ((Bank) ((ResultsRow) res.get(1)).get(0)).getName()); }
/** Test that transactions can be aborted */ public void testAbortTransactions() throws Exception { Address address1 = new Address(); address1.setAddress("Address 3"); Address address2 = new Address(); address2.setAddress("Address 4"); Query q = new Query(); QueryClass qcAddress = new QueryClass(Address.class); QueryField qf = new QueryField(qcAddress, "address"); ConstraintSet cs1 = new ConstraintSet(ConstraintOp.OR); cs1.addConstraint(new SimpleConstraint(qf, ConstraintOp.MATCHES, new QueryValue("Address%"))); q.addToSelect(qcAddress); q.addFrom(qcAddress); q.addToOrderBy(qf); q.setConstraint(cs1); Results res = writer.execute(q); assertEquals(res.toString(), 0, res.size()); res = realOs.execute(q); assertEquals(res.toString(), 0, res.size()); writer.beginTransaction(); assertTrue(writer.isInTransaction()); writer.store(address1); writer.store(address2); // TODO: These lines now fail, because we do not allow querying on writers with uncommitted // data. The writer should relax this restriction. res = writer.execute(q); assertEquals(2, res.size()); res = realOs.execute(q); assertEquals(res.toString(), 0, res.size()); writer.abortTransaction(); assertFalse(writer.isInTransaction()); // Should be nothing there unless we commit res = writer.execute(q); assertEquals(res.toString(), 0, res.size()); res = realOs.execute(q); assertEquals(res.toString(), 0, res.size()); }
public void testLoad() throws Exception { TSVFileReaderTask tsvTask = new TSVFileReaderTask(); tsvTask.setIgnoreDuplicates(true); tsvTask.setIntegrationWriterAlias("integration.unittestmulti"); tsvTask.setSourceName("testsource"); cleanObjects(tsvTask.getDirectDataLoader().getIntegrationWriter()); File tempFile = File.createTempFile("TSVFileReaderTaskTest", "tmp"); FileWriter fw = new FileWriter(tempFile); InputStream is = getClass().getClassLoader().getResourceAsStream("TSVFileReaderTaskTest.tsv"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; while ((line = br.readLine()) != null) { fw.write(line + "\n"); } fw.close(); FileSet fileSet = new FileSet(); fileSet.setFile(tempFile); tsvTask.addFileSet(fileSet); InputStream confInputStream = getClass().getClassLoader().getResourceAsStream("TSVFileReaderTaskTest.properties"); DelimitedFileConfiguration dfc = new DelimitedFileConfiguration(model, confInputStream); tsvTask.executeInternal(dfc, tempFile); // Check the results to see if we have some data... ObjectStore os = tsvTask.getDirectDataLoader().getIntegrationWriter().getObjectStore(); Query q = new Query(); QueryClass empQueryClass = new QueryClass(Employee.class); QueryField qf0 = new QueryField(empQueryClass, "age"); QueryField qf1 = new QueryField(empQueryClass, "name"); QueryField qf2 = new QueryField(empQueryClass, "fullTime"); q.addToSelect(qf0); q.addToSelect(qf1); q.addToSelect(qf2); q.addFrom(empQueryClass); q.addToOrderBy(qf1); Results r = os.execute(q); if (r.size() != 3) { for (List<Object> rr : (List<List<Object>>) ((List) r)) { System.err.print("row: "); for (Object obj : rr) { System.err.print("{" + obj + "} "); } System.err.println(); } } assertEquals(3, r.size()); List expectedRow0 = Arrays.asList(new Object[] {new Integer(10), "EmployeeA1", Boolean.FALSE}); assertEquals(expectedRow0, r.get(0)); List expectedRow1 = Arrays.asList(new Object[] {new Integer(20), "EmployeeA2", Boolean.TRUE}); assertEquals(expectedRow1, r.get(1)); List expectedRow2 = Arrays.asList(new Object[] {new Integer(0), "EmployeeA3", Boolean.FALSE}); assertEquals(expectedRow2, r.get(2)); }