📄 collectiontest.java
字号:
testStore = null; } } /** * Is overridden in XACollectionTest. */ protected TransactionRunner newTransactionRunner(Environment env) throws DatabaseException { return new TransactionRunner(env); } void testCreation(StoredContainer cont, int expectSize) throws Exception { assertEquals(index != null, cont.isSecondary()); assertEquals(testStore.isOrdered(), cont.isOrdered()); assertEquals(testStore.areKeysRenumbered(), cont.areKeysRenumbered()); assertEquals(testStore.areDuplicatesAllowed(), cont.areDuplicatesAllowed()); assertEquals(testEnv.isTxnMode(), cont.isTransactional()); assertEquals(expectSize, cont.size()); } void testMapCreation(Map map) throws Exception { assertTrue(map.values() instanceof Set); assertEquals(testStore.isOrdered(), map.keySet() instanceof SortedSet); assertEquals(testStore.isOrdered(), map.entrySet() instanceof SortedSet); assertEquals(testStore.isOrdered() && isEntityBinding, map.values() instanceof SortedSet); } void testUnindexed() throws Exception { // create primary map if (testStore.isOrdered()) { if (isEntityBinding) { smap = new StoredSortedMap(store, keyBinding, entityBinding, testStore.getKeyAssigner()); valueSet = new StoredSortedValueSet(store, entityBinding, true); } else { smap = new StoredSortedMap(store, keyBinding, valueBinding, testStore.getKeyAssigner()); // sorted value set is not possible since key cannot be derived // for performing subSet, etc. } keySet = new StoredSortedKeySet(store, keyBinding, true); map = smap; } else { if (isEntityBinding) { map = new StoredMap(store, keyBinding, entityBinding, testStore.getKeyAssigner()); valueSet = new StoredValueSet(store, entityBinding, true); } else { map = new StoredMap(store, keyBinding, valueBinding, testStore.getKeyAssigner()); valueSet = new StoredValueSet(store, valueBinding, true); } smap = null; keySet = new StoredKeySet(store, keyBinding, true); } imap = map; // create primary list if (testStore.hasRecNumAccess()) { if (isEntityBinding) { ilist = new StoredList(store, entityBinding, testStore.getKeyAssigner()); } else { ilist = new StoredList(store, valueBinding, testStore.getKeyAssigner()); } list = ilist; } else { try { if (isEntityBinding) { ilist = new StoredList(store, entityBinding, testStore.getKeyAssigner()); } else { ilist = new StoredList(store, valueBinding, testStore.getKeyAssigner()); } fail(); } catch (IllegalArgumentException expected) {} } testCreation(map, 0); if (list != null) { testCreation(list, 0); assertNotNull(smap); } testMapCreation(map); addAll(); testAll(); } void testIndexed() throws Exception { // create primary map if (isEntityBinding) { map = new StoredMap(store, keyBinding, entityBinding, testStore.getKeyAssigner()); } else { map = new StoredMap(store, keyBinding, valueBinding, testStore.getKeyAssigner()); } imap = map; smap = null; // create primary list if (testStore.hasRecNumAccess()) { if (isEntityBinding) { list = new StoredList(store, entityBinding, testStore.getKeyAssigner()); } else { list = new StoredList(store, valueBinding, testStore.getKeyAssigner()); } ilist = list; } addAll(); readAll(); // create indexed map (keySet/valueSet) if (testStore.isOrdered()) { if (isEntityBinding) { map = smap = new StoredSortedMap(index, keyBinding, entityBinding, true); valueSet = new StoredSortedValueSet(index, entityBinding, true); } else { map = smap = new StoredSortedMap(index, keyBinding, valueBinding, true); // sorted value set is not possible since key cannot be derived // for performing subSet, etc. } keySet = new StoredSortedKeySet(index, keyBinding, true); } else { if (isEntityBinding) { map = new StoredMap(index, keyBinding, entityBinding, true); valueSet = new StoredValueSet(index, entityBinding, true); } else { map = new StoredMap(index, keyBinding, valueBinding, true); valueSet = new StoredValueSet(index, valueBinding, true); } smap = null; keySet = new StoredKeySet(index, keyBinding, true); } // create indexed list if (testStore.hasRecNumAccess()) { if (isEntityBinding) { list = new StoredList(index, entityBinding, true); } else { list = new StoredList(index, valueBinding, true); } } else { try { if (isEntityBinding) { list = new StoredList(index, entityBinding, true); } else { list = new StoredList(index, valueBinding, true); } fail(); } catch (IllegalArgumentException expected) {} } testCreation(map, maxKey); testCreation((StoredContainer) map.values(), maxKey); testCreation((StoredContainer) map.keySet(), maxKey); testCreation((StoredContainer) map.entrySet(), maxKey); if (list != null) { testCreation(list, maxKey); assertNotNull(smap); } testMapCreation(map); testAll(); } void testAll() throws Exception { checkKeySetAndValueSet(); readAll(); updateAll(); readAll(); if (!map.areKeysRenumbered()) { removeOdd(); readEven(); addOdd(); readAll(); removeOddIter(); readEven(); if (imap.areDuplicatesAllowed()) { addOddDup(); } else { addOdd(); } readAll(); removeOddEntry(); readEven(); addOdd(); readAll(); if (isEntityBinding) { removeOddEntity(); readEven(); addOddEntity(); readAll(); } bulkOperations(); } if (isListAddAllowed()) { removeOddList(); readEvenList(); addOddList(); readAll(); if (!isEntityBinding) { removeOddListValue(); readEvenList(); addOddList(); readAll(); } } if (list != null) { bulkListOperations(); } else { listOperationsNotAllowed(); } if (smap != null) { readWriteRange(SUB, 1, 1); readWriteRange(HEAD, 1, 1); readWriteRange(SUB, 1, maxKey); readWriteRange(HEAD, 1, maxKey); readWriteRange(TAIL, 1, maxKey); readWriteRange(SUB, 1, 3); readWriteRange(HEAD, 1, 3); readWriteRange(SUB, 2, 2); readWriteRange(SUB, 2, maxKey); readWriteRange(TAIL, 2, maxKey); readWriteRange(SUB, maxKey, maxKey); readWriteRange(TAIL, maxKey, maxKey); readWriteRange(SUB, maxKey + 1, maxKey + 1); readWriteRange(TAIL, maxKey + 1, maxKey + 1); readWriteRange(SUB, 0, 0); readWriteRange(HEAD, 0, 0); } updateAll(); readAll(); if (map.areDuplicatesAllowed()) { readWriteDuplicates(); readAll(); } else { duplicatesNotAllowed(); readAll(); } if (testEnv.isCdbMode()) { testCdbLocking(); } removeAll(); if (isListAddAllowed()) { testIterAddList(); clearAll(); } if (imap.areDuplicatesAllowed()) { testIterAddDuplicates(); clearAll(); } if (isListAddAllowed()) { addAllList(); readAll(); removeAllList(); } appendAll(); } void checkKeySetAndValueSet() { // use bulk operations to check that explicitly constructed // keySet/valueSet are equivalent assertTrue(imap.keySet().equals(keySet)); if (valueSet != null) { assertTrue(imap.values().equals(valueSet)); } } Iterator iterator(Collection storedCollection) { if (testStoredIterator) { return ((StoredCollection) storedCollection).storedIterator(); } else { return storedCollection.iterator(); } } void addAll() throws Exception { writeRunner.run(new TransactionWorker() { public void doWork() throws Exception { assertTrue(imap.isEmpty()); Iterator iter = iterator(imap.entrySet()); try { assertTrue(!iter.hasNext()); } finally { StoredIterator.close(iter); } assertEquals(0, imap.keySet().toArray().length); assertEquals(0, imap.keySet().toArray(new Object[0]).length); assertEquals(0, imap.entrySet().toArray().length); assertEquals(0, imap.entrySet().toArray(new Object[0]).length); assertEquals(0, imap.values().toArray().length); assertEquals(0, imap.values().toArray(new Object[0]).length); for (int i = beginKey; i <= endKey; i += 1) { Long key = makeKey(i); Object val = makeVal(i); assertNull(imap.get(key)); assertTrue(!imap.keySet().contains(key)); assertTrue(!imap.values().contains(val)); assertNull(imap.put(key, val)); assertEquals(val, imap.get(key)); assertTrue(imap.keySet().contains(key)); assertTrue(imap.values().contains(val)); assertTrue(imap.duplicates(key).contains(val)); if (!imap.areDuplicatesAllowed()) { assertEquals(val, imap.put(key, val)); } checkDupsSize(1, imap.duplicates(key)); } assertTrue(!imap.isEmpty()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -