View Javadoc
1   package ejava.jpa.examples.tuning.benchmarks;
2   
3   import static org.junit.Assert.*;
4   
5   import org.junit.Before;
6   import org.junit.BeforeClass;
7   import org.junit.Test;
8   
9   import ejava.jpa.examples.tuning.TestBase;
10  import ejava.jpa.examples.tuning.TestLabel;
11  import ejava.jpa.examples.tuning.bo.Person;
12  import ejava.jpa.examples.tuning.dao.MovieDAOImpl;
13  
14  /**
15   * This test will perform nested queries that can either be expressed as subqueries
16   * or repeated loops in the DAO.
17   */
18  public class LoopQuery extends TestBase {
19  	protected static Person kevinBacon;
20  	protected MovieDAOImpl dao;
21  	
22  	@BeforeClass 
23  	public static void setUpClass() {
24  		kevinBacon = getDAO().getKevinBacon();
25  	}
26  	
27  	@Before
28  	public void setUp() {
29  		dao=getDAO();
30  	}
31  	
32  	/*
33  	@TestLabel(label="DAO Loop")
34  	@Test
35  	public void daoLoop() {
36  		log.info("" + dao.oneStepFromPersonByDAO(kevinBacon).size() + " people found");
37  	}
38  	
39  	@TestLabel(label="DB Loop Distinct")
40  	@Test
41  	public void dbLoopDistinct() {
42  		log.info("" + dao.oneStepFromPersonByDB(kevinBacon).size() + " people found");
43  	}
44  */
45  	private static int PAGE_SIZE=50;
46  	
47  	@TestLabel(label="DAO Page 0")
48  	@Test
49  	public void daoPage0() {
50  		final int offset=0*PAGE_SIZE;
51  		assertEquals(PAGE_SIZE,dao.oneStepFromPersonByDAO(kevinBacon, offset, PAGE_SIZE, "role.actor.person.lastName ASC").size());
52  	}
53  	@TestLabel(label="DB Page 0")
54  	@Test
55  	public void dbPage0() {
56  		final int offset=0*PAGE_SIZE;
57  		assertEquals(PAGE_SIZE,dao.oneStepFromPersonByDB(kevinBacon, offset, PAGE_SIZE, "role.actor.person.lastName ASC").size());
58  	}
59  	
60  	@TestLabel(label="DAO Page 10")
61  	@Test
62  	public void daoPage10() {
63  		final int offset=10*PAGE_SIZE;
64  		assertEquals(PAGE_SIZE,dao.oneStepFromPersonByDAO(kevinBacon, offset, PAGE_SIZE, "role.actor.person.lastName ASC").size());
65  	}
66  	@TestLabel(label="DB Page 10")
67  	@Test
68  	public void dbPage10() {
69  		final int offset=10*PAGE_SIZE;
70  		assertEquals(PAGE_SIZE,dao.oneStepFromPersonByDB(kevinBacon, offset, PAGE_SIZE, "role.actor.person.lastName ASC").size());
71  	}
72  	
73  	@TestLabel(label="DAO Page 50")
74  	@Test
75  	public void daoPage50() {
76  		final int offset=50*PAGE_SIZE;
77  		assertEquals(PAGE_SIZE,dao.oneStepFromPersonByDAO(kevinBacon, offset, PAGE_SIZE, "role.actor.person.lastName ASC").size());
78  	}
79  	@TestLabel(label="DB Page 50")
80  	@Test
81  	public void dbPage50() {
82  		final int offset=50*PAGE_SIZE;
83  		assertEquals(PAGE_SIZE,dao.oneStepFromPersonByDB(kevinBacon, offset, PAGE_SIZE, "role.actor.person.lastName ASC").size());
84  	}
85  	
86  }