Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,17 @@
package com.baeldung.libraries.hikaricp;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class HikariCPIntegrationTest {
@Test
public void givenConnection_thenFetchDbData() {
List<Employee> employees = HikariCPDemo.fetchData();
assertEquals(4, employees.size());
}
}
@@ -0,0 +1,111 @@
package com.baeldung.libraries.jdo;
import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
import org.datanucleus.metadata.PersistenceUnitMetaData;
import org.junit.Test;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;
import javax.jdo.Transaction;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class GuideToJDOIntegrationTest {
@Test
public void givenProduct_WhenNewThenPerformTransaction() {
PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null);
pumd.addClassName("com.baeldung.libraries.jdo.Product");
pumd.setExcludeUnlistedClasses();
pumd.addProperty("javax.jdo.option.ConnectionDriverName", "org.h2.Driver");
pumd.addProperty("javax.jdo.option.ConnectionURL", "jdbc:h2:mem:mypersistence");
pumd.addProperty("javax.jdo.option.ConnectionUserName", "sa");
pumd.addProperty("javax.jdo.option.ConnectionPassword", "");
pumd.addProperty("datanucleus.autoCreateSchema", "true");
pumd.addProperty("datanucleus.schema.autoCreateTables", "true");
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
for (int i = 0; i < 100; i++) {
String nam = "Product-" + i;
Product productx = new Product(nam, (double) i);
pm.makePersistent(productx);
}
tx.commit();
} catch (Throwable thr) {
fail("Failed test : " + thr.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pmf.close();
}
@Test
public void givenProduct_WhenQueryThenExist() {
PersistenceUnitMetaData pumd = new PersistenceUnitMetaData("dynamic-unit", "RESOURCE_LOCAL", null);
pumd.addClassName("com.baeldung.libraries.jdo.Product");
pumd.setExcludeUnlistedClasses();
pumd.addProperty("javax.jdo.option.ConnectionDriverName", "org.h2.Driver");
pumd.addProperty("javax.jdo.option.ConnectionURL", "jdbc:h2:mem:mypersistence");
pumd.addProperty("javax.jdo.option.ConnectionUserName", "sa");
pumd.addProperty("javax.jdo.option.ConnectionPassword", "");
pumd.addProperty("datanucleus.autoCreateSchema", "true");
pumd.addProperty("datanucleus.schema.autoCreateTables", "true");
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Product product = new Product("Tablet", 80.0);
pm.makePersistent(product);
Product product2 = new Product("Phone", 20.0);
pm.makePersistent(product2);
Product product3 = new Product("Laptop", 200.0);
pm.makePersistent(product3);
tx.commit();
} catch (Throwable thr) {
fail("Failed test : " + thr.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pmf.close();
PersistenceManagerFactory pmf2 = new JDOPersistenceManagerFactory(pumd, null);
PersistenceManager pm2 = pmf2.getPersistenceManager();
Transaction tx2 = pm2.currentTransaction();
try {
tx2.begin();
@SuppressWarnings("rawtypes")
Query q = pm2.newQuery("SELECT FROM " + Product.class.getName() + " WHERE price == 200");
@SuppressWarnings("unchecked")
List<Product> products = (List<Product>) q.execute();
for (Product p : products) {
assertEquals("Laptop", p.name);
}
tx2.commit();
} finally {
if (tx2.isActive()) {
tx2.rollback();
}
pm2.close();
}
}
}
@@ -0,0 +1,168 @@
package com.baeldung.libraries.ormlite;
import com.j256.ormlite.dao.CloseableWrappedIterable;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.jdbc.JdbcPooledConnectionSource;
import com.j256.ormlite.table.TableUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import static org.junit.Assert.*;
public class ORMLiteIntegrationTest {
private static JdbcPooledConnectionSource connectionSource;
private static Dao<Library, Long> libraryDao;
private static Dao<Book, Long> bookDao;
@BeforeClass
public static void setup() throws SQLException {
connectionSource = new JdbcPooledConnectionSource("jdbc:h2:mem:myDb");
TableUtils.createTableIfNotExists(connectionSource, Library.class);
TableUtils.createTableIfNotExists(connectionSource, Address.class);
TableUtils.createTableIfNotExists(connectionSource, Book.class);
libraryDao = DaoManager.createDao(connectionSource, Library.class);
bookDao = DaoManager.createDao(connectionSource, Book.class);
}
@Test
public void givenDAO_whenCRUD_thenOk() throws SQLException {
Library library = new Library();
library.setName("My Library");
libraryDao.create(library);
Library result = libraryDao.queryForId(library.getLibraryId());
assertEquals("My Library", result.getName());
library.setName("My Other Library");
libraryDao.update(library);
libraryDao.delete(library);
}
@Test
public void whenLoopDao_thenOk() throws SQLException {
Library library1 = new Library();
library1.setName("My Library");
libraryDao.create(library1);
Library library2 = new Library();
library2.setName("My Other Library");
libraryDao.create(library2);
libraryDao.forEach(lib -> {
System.out.println(lib.getName());
});
}
@Test
public void givenIterator_whenLoop_thenOk() throws SQLException, IOException {
Library library1 = new Library();
library1.setName("My Library");
libraryDao.create(library1);
Library library2 = new Library();
library2.setName("My Other Library");
libraryDao.create(library2);
try (CloseableWrappedIterable<Library> wrappedIterable = libraryDao.getWrappedIterable()) {
wrappedIterable.forEach(lib -> {
System.out.println(lib.getName());
});
}
}
@Test
public void givenCustomDao_whenSave_thenOk() throws SQLException, IOException {
Library library = new Library();
library.setName("My Library");
LibraryDao customLibraryDao = DaoManager.createDao(connectionSource, Library.class);
customLibraryDao.create(library);
assertEquals(1, customLibraryDao.findByName("My Library")
.size());
}
@Test
public void whenSaveForeignField_thenOk() throws SQLException, IOException {
Library library = new Library();
library.setName("My Library");
library.setAddress(new Address("Main Street nr 20"));
libraryDao.create(library);
Dao<Address, Long> addressDao = DaoManager.createDao(connectionSource, Address.class);
assertEquals(1, addressDao.queryForEq("addressLine", "Main Street nr 20")
.size());
}
@Test
public void whenSaveForeignCollection_thenOk() throws SQLException, IOException {
Library library = new Library();
library.setName("My Library");
libraryDao.create(library);
libraryDao.refresh(library);
library.getBooks()
.add(new Book("1984"));
Book book = new Book("It");
book.setLibrary(library);
bookDao.create(book);
assertEquals(2, bookDao.queryForEq("library_id", library)
.size());
}
@Test
public void whenGetLibrariesWithMoreThanOneBook_thenOk() throws SQLException, IOException {
Library library = new Library();
library.setName("My Library");
libraryDao.create(library);
Library library2 = new Library();
library2.setName("My Other Library");
libraryDao.create(library2);
libraryDao.refresh(library);
libraryDao.refresh(library2);
library.getBooks()
.add(new Book("Book1"));
library2.getBooks()
.add(new Book("Book2"));
library2.getBooks()
.add(new Book("Book3"));
List<Library> libraries = libraryDao.queryBuilder()
.where()
.in("libraryId", bookDao.queryBuilder()
.selectColumns("library_id")
.groupBy("library_id")
.having("count(*) > 1"))
.query();
assertEquals(1, libraries.size());
}
@After
public void clear() throws SQLException {
TableUtils.clearTable(connectionSource, Library.class);
TableUtils.clearTable(connectionSource, Book.class);
TableUtils.clearTable(connectionSource, Address.class);
}
@AfterClass
public static void tearDown() throws SQLException, IOException {
connectionSource.close();
}
}
@@ -0,0 +1,37 @@
package com.baeldung.libraries.reladomo;
import com.gs.fw.common.mithra.test.ConnectionManagerForTests;
import com.gs.fw.common.mithra.test.MithraTestResource;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class ReladomoIntegrationTest {
private MithraTestResource mithraTestResource;
@Before
public void setUp() throws Exception {
this.mithraTestResource = new MithraTestResource("reladomo/ReladomoTestConfig.xml");
final ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstanceForDbName("testDb");
this.mithraTestResource.createSingleDatabase(connectionManager);
mithraTestResource.addTestDataToDatabase("reladomo/test-data.txt", connectionManager);
this.mithraTestResource.setUp();
}
@Test
public void whenGetTestData_thenOk() {
Employee employee = EmployeeFinder.findByPrimaryKey(1);
assertEquals(employee.getName(), "Paul");
}
@After
public void tearDown() throws Exception {
this.mithraTestResource.tearDown();
}
}
@@ -0,0 +1,7 @@
<MithraRuntime>
<ConnectionManager className="com.gs.fw.common.mithra.test.ConnectionManagerForTests">
<Property name="resourceName" value="testDb"/>
<MithraObjectConfiguration className="com.baeldung.libraries.reladomo.Department" cacheType="partial"/>
<MithraObjectConfiguration className="com.baeldung.libraries.reladomo.Employee" cacheType="partial"/>
</ConnectionManager>
</MithraRuntime>
@@ -0,0 +1,7 @@
class com.baeldung.libraries.reladomo.Department
id, name
1, "Marketing"
class com.baeldung.libraries.reladomo.Employee
id, name
1, "Paul"