KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > unitTests > store > T_Heap


1 /*
2
3    Derby - Class org.apache.derbyTesting.unitTests.store.T_Heap
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.unitTests.store;
23
24 // impl imports are the preferred way to create unit tests.
25
import org.apache.derbyTesting.unitTests.harness.T_Generic;
26 import org.apache.derbyTesting.unitTests.harness.T_Fail;
27
28 import org.apache.derby.impl.store.access.heap.*;
29
30 import java.util.Properties JavaDoc;
31
32 import java.io.PrintWriter JavaDoc;
33
34 import org.apache.derby.iapi.services.context.ContextService;
35
36 import org.apache.derby.iapi.services.monitor.Monitor;
37 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
38
39 import org.apache.derby.iapi.error.StandardException;
40 import org.apache.derby.iapi.store.access.AccessFactory;
41 import org.apache.derby.iapi.store.access.ConglomerateController;
42 import org.apache.derby.iapi.store.access.Qualifier;
43 import org.apache.derby.iapi.types.RowLocation;
44 import org.apache.derby.iapi.store.access.ScanController;
45 import org.apache.derby.iapi.store.access.TransactionController;
46
47 import org.apache.derby.iapi.reference.Property;
48
49 import java.util.Properties JavaDoc;
50
51 public class T_Heap extends T_Generic
52 {
53     private static final String JavaDoc testService = "heapTest";
54     /*
55     ** Methods required by T_Generic
56     */

57
58     public String JavaDoc getModuleToTestProtocolName() {
59         return AccessFactory.MODULE;
60     }
61
62     /**
63         @exception T_Fail test failed.
64     */

65     protected void runTests() throws T_Fail
66     {
67         AccessFactory store = null;
68         TransactionController tc = null;
69         boolean pass = false;
70
71         out.println("executing heap test");
72
73         // don't automatic boot this service if it gets left around
74
if (startParams == null) {
75             startParams = new Properties JavaDoc();
76         }
77         startParams.put(Property.NO_AUTO_BOOT, Boolean.TRUE.toString());
78         // remove the service directory to ensure a clean run
79
startParams.put(Property.DELETE_ON_CREATE, Boolean.TRUE.toString());
80
81         // see if we are testing encryption
82
startParams = T_Util.setEncryptionParam(startParams);
83
84         try {
85             store = (AccessFactory) Monitor.createPersistentService(getModuleToTestProtocolName(),
86             testService, startParams);
87         } catch (StandardException mse) {
88             throw T_Fail.exceptionFail(mse);
89         }
90
91         if (store == null) {
92             throw T_Fail.testFailMsg(getModuleToTestProtocolName() + " service not started.");
93         }
94         REPORT("(unitTestMain) Testing " + testService);
95
96         try {
97
98             tc = store.getTransaction(
99                     ContextService.getFactory().getCurrentContextManager());
100
101             if (t_001(tc))
102             {
103                 pass = true;
104             }
105
106             tc.commit();
107             tc.destroy();
108         }
109         catch (StandardException e)
110         {
111             System.out.println("got an exception.");
112             String JavaDoc msg = e.getMessage();
113             if (msg == null)
114                 msg = e.getClass().getName();
115             REPORT(msg);
116             throw T_Fail.exceptionFail(e);
117         }
118
119         if (!pass)
120             throw T_Fail.testFailMsg("T_Heap test failed");
121     }
122
123     /*
124      * Test Qualifiers.
125      */

126     protected boolean t_001(TransactionController tc)
127         throws StandardException, T_Fail
128     {
129         REPORT("Starting t_001");
130
131         T_QualifierTest q_test =
132             new T_QualifierTest(
133                 "heap", // create a heap
134
null, // properties
135
false, // not temporary
136
out,
137                 T_QualifierTest.ORDER_NONE); // unordered data
138

139         boolean test_result = q_test.t_testqual(tc);
140
141         if (!test_result)
142             throw T_Fail.testFailMsg("T_Heap.t_001 failed");
143
144         REPORT("Ending t_001");
145
146         return(test_result);
147     }
148 }
149
Popular Tags