001: /*
002: This source file is part of Smyle, a database library.
003: For up-to-date information, see http://www.drjava.de/smyle
004: Copyright (C) 2001 Stefan Reich (doc@drjava.de)
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: For full license text, see doc/license/lgpl.txt in this distribution
021: */
022:
023: package drjava.smyle.tests;
024:
025: import java.util.*;
026: import junit.framework.*;
027: import drjava.smyle.core.*;
028:
029: public class IndexAdvisorTest extends TestCase {
030: public IndexAdvisorTest(String name) {
031: super (name);
032: }
033:
034: IndexAdvisor<String> advisor;
035: String indexedField;
036:
037: //boolean rotate;
038:
039: public void setUp() {
040: advisor = new IndexAdvisor<String>(/*new StringMarDemar()*/);
041: //rotate = false;
042: }
043:
044: public void testInitialAdvise() {
045: assertNull(advisor.fieldToIndex());
046: }
047:
048: public void testNoFieldsInQuery() {
049: // should handle this gracefully
050: advisor.queryPerformed(new String[0], 1000000);
051: assertNull(advisor.fieldToIndex());
052: }
053:
054: public void testAdviseAfterQuery() {
055: advisor.queryPerformed(new String[] { "age" }, 5000);
056: assertEquals("age", advisor.fieldToIndex());
057: }
058:
059: public void testFreeze() {
060: advisor.freeze();
061: advisor.queryPerformed(new String[] { "age" }, 5000);
062: assertNull(advisor.fieldToIndex());
063: }
064:
065: public void testNoImplicitHurdleChange() {
066: advisor.queryPerformed(new String[] { "age" }, 5000);
067: assertEquals("age", advisor.fieldToIndex());
068: advisor.queryPerformed(new String[] { "name" }, 5001);
069: assertEquals("name", advisor.fieldToIndex());
070: }
071:
072: /** another field needs twice as many accesses before it becomes the index field */
073: public void testAdviseChange() throws Exception {
074: // query by age
075: advisor.queryPerformed(new String[] { "age" }, 5000);
076: assertEquals("age", advisor.fieldToIndex());
077:
078: rotate();
079:
080: // make age the indexed field
081: acceptAdvise();
082:
083: // query by name
084: advisor.queryPerformed(new String[] { "name" }, 9999);
085: assertEquals("age", advisor.fieldToIndex());
086:
087: rotate();
088:
089: // query by name some more
090: advisor.queryPerformed(new String[] { "name" }, 1);
091: assertEquals("name", advisor.fieldToIndex());
092:
093: rotate();
094:
095: // make name the indexed field
096: acceptAdvise();
097:
098: rotate();
099:
100: // query by age again
101: advisor.queryPerformed(new String[] { "age" }, 14999);
102: assertEquals("name", advisor.fieldToIndex());
103:
104: rotate();
105:
106: // query by age some more
107: advisor.queryPerformed(new String[] { "age" }, 1);
108: assertEquals("age", advisor.fieldToIndex());
109: }
110:
111: /*public void testAdviseChangeRotate() throws Exception {
112: rotate = true;
113: testAdviseChange();
114: }*/
115:
116: void acceptAdvise() {
117: advisor.setIndexedField(indexedField = advisor.fieldToIndex());
118: }
119:
120: void rotate() throws Exception {
121: /*if (rotate) {
122: MasterChunkManager cm = new DefaultChunkManager(new MemoryDisk(), DiskStore.VERSION);
123: ChunkRef cr = advisor.saveStats(cm);
124:
125: // gc
126: BitSet whiteList = new BitSet();
127: advisor.collectChunks(whiteList, cr);
128: cm.deleteEverythingBut(whiteList);
129:
130: advisor = new IndexAdvisor<String>(new StringMarDemar(), cm, cr);
131: advisor.setIndexedField(indexedField);
132: }*/
133: }
134: }
|