/** * Test the removing of the element in the {@link ArrayBasedStorageLeaf}. * * @throws IndexingException * {@link IndexingException} */ @Test public void removeElement() throws IndexingException { ArrayBasedStorageLeaf<DefaultData> arrayBasedStorageLeaf = new ArrayBasedStorageLeaf<>(); DefaultData defaultData = mock(DefaultData.class); when(defaultData.getId()).thenReturn(1L); arrayBasedStorageLeaf.put(defaultData); assertThat(arrayBasedStorageLeaf.getAndRemove(defaultData), is(notNullValue())); assertThat(arrayBasedStorageLeaf.get(defaultData), is(nullValue())); assertThat(arrayBasedStorageLeaf.query(storageIndexQuery), is(empty())); // Test for forkJoinPool assertThat(arrayBasedStorageLeaf.query(storageIndexQuery, forkJoinPool), is(empty())); }
/** * {@inheritDoc} */ @Override public List<IStorageDescriptor> query(IIndexQuery query, ForkJoinPool forkJoinPool) { return forkJoinPool.invoke(getTaskForForkJoinQuery(query)); }
public List<IStorageDescriptor> query(IIndexQuery query) { if (query instanceof StorageIndexQuery) { return this.queryWithStorageQuery((StorageIndexQuery) query); } else { readLock.lock();
/** * Tests that the indexing the same element in the {@link ArrayBasedStorageLeaf} will thrown a * exception. * * @throws IndexingException * {@link IndexingException} */ @Test(expectedExceptions = { IndexingException.class }) public void indexSameElement() throws IndexingException { ArrayBasedStorageLeaf<DefaultData> arrayBasedStorageLeaf = new ArrayBasedStorageLeaf<>(); DefaultData defaultData = mock(DefaultData.class); when(defaultData.getId()).thenReturn(1L); arrayBasedStorageLeaf.put(defaultData); arrayBasedStorageLeaf.put(defaultData); }
/** * Get and getAndRemove on empty leaf should return <code>null</code>. */ @Test public void getOnEmpyLeaf() { DefaultData element = mock(DefaultData.class); when(element.getId()).thenReturn(10L); assertThat(arrayBasedStorageLeaf.get(element), is(nullValue())); assertThat(arrayBasedStorageLeaf.getAndRemove(element), is(nullValue())); }
/** * Init. */ @BeforeMethod public void init() { arrayBasedStorageLeaf = new ArrayBasedStorageLeaf<>(LEAF_ID); }
/** * With minIds we can limit the number of elements returned. * * @throws IndexingException */ @Test public void minIdQuery() throws IndexingException { addElements(arrayBasedStorageLeaf, 100); IndexQuery indexQuery = mock(IndexQuery.class); when(indexQuery.getMinId()).thenReturn(51L); List<IStorageDescriptor> result = arrayBasedStorageLeaf.query(indexQuery); assertThat(result, hasSize(50)); for (IStorageDescriptor descriptor : result) { assertThat(descriptor.getChannelId(), is(LEAF_ID)); } }
/** * Indexing same element twice should raise an exception. * * @throws IndexingException */ @Test(expectedExceptions = { IndexingException.class }) public void sameElementIndexedTwice() throws IndexingException { DefaultData element = mock(DefaultData.class); when(element.getId()).thenReturn(10L); arrayBasedStorageLeaf.put(element); arrayBasedStorageLeaf.put(element); }
/** * Test the creation of new component when leaf should be created. */ @Test public void nextComponentIsLeaf() { int id = 1; storageBranchIndexer = new StorageBranchIndexer<>(delegateIndexer, null, id, true); DefaultData defaultData = mock(DefaultData.class); InvocationSequenceData invocationSequenceData = mock(InvocationSequenceData.class); // first pass id IStorageTreeComponent<DefaultData> component = storageBranchIndexer.getNextTreeComponent(defaultData); assertThat(component, is(instanceOf(LeafWithNoDescriptors.class))); LeafWithNoDescriptors<DefaultData> leaf = (LeafWithNoDescriptors<DefaultData>) component; assertThat(leaf.getId(), is(id)); component = storageBranchIndexer.getNextTreeComponent(invocationSequenceData); assertThat(component, is(instanceOf(ArrayBasedStorageLeaf.class))); ArrayBasedStorageLeaf<DefaultData> arrayLeaf = (ArrayBasedStorageLeaf<DefaultData>) component; assertThat(arrayLeaf.getId(), is(id)); storageBranchIndexer = new StorageBranchIndexer<>(delegateIndexer, null, id, false); // then don't pass id component = storageBranchIndexer.getNextTreeComponent(defaultData); assertThat(component, is(instanceOf(LeafWithNoDescriptors.class))); leaf = (LeafWithNoDescriptors<DefaultData>) component; assertThat(leaf.getId(), is(not(id))); component = storageBranchIndexer.getNextTreeComponent(invocationSequenceData); assertThat(component, is(instanceOf(ArrayBasedStorageLeaf.class))); arrayLeaf = (ArrayBasedStorageLeaf<DefaultData>) component; assertThat(arrayLeaf.getId(), is(not(id))); }
/** * {@inheritDoc} */ @Override public IStorageDescriptor put(E element) throws IndexingException { if (null == element) { throw new IndexingException("Element to index can not be null."); } else if (0 == element.getId()) { throw new IndexingException("Element to index can not have ID that is equal to zero."); } StorageDescriptor descriptor = new StorageDescriptor(this.id); if (insertIntoArrays(element.getId(), descriptor.getSimpleStorageDescriptor())) { return descriptor; } else { throw new IndexingException("Element already indexed."); } }
return new ArrayBasedStorageLeaf<>(id); } else { return new ArrayBasedStorageLeaf<>();
/** * Exclude/include ID also can be define in query. * * @throws IndexingException */ @Test public void includeExcludeIdQuery() throws IndexingException { addElements(arrayBasedStorageLeaf, 100); StorageIndexQuery indexQuery = mock(StorageIndexQuery.class); List<Long> includeIds = new ArrayList<>(); List<Long> excludeIds = new ArrayList<>(); when(indexQuery.getIncludeIds()).thenReturn(includeIds); when(indexQuery.getExcludeIds()).thenReturn(excludeIds); includeIds.add(50L); List<IStorageDescriptor> result = arrayBasedStorageLeaf.query(indexQuery); assertThat(result, hasSize(1)); excludeIds.add(50L); result = arrayBasedStorageLeaf.query(indexQuery); assertThat(result, is(empty())); when(indexQuery.getIncludeIds()).thenReturn(null); result = arrayBasedStorageLeaf.query(indexQuery); assertThat(result, hasSize(99)); when(indexQuery.getMinId()).thenReturn(100L); result = arrayBasedStorageLeaf.query(indexQuery); assertThat(result, hasSize(1)); }
ArrayBasedStorageLeaf<DefaultData> arrayBasedStorageLeaf = new ArrayBasedStorageLeaf<>(); while (i <= entries) { when(defaultData.getId()).thenReturn(i); IStorageDescriptor storageDescriptor = arrayBasedStorageLeaf.put(defaultData); storageDescriptor.setPositionAndSize(totalSize, i); totalSize += i; when(defaultData.getId()).thenReturn(removeId); assertThat(arrayBasedStorageLeaf.getAndRemove(defaultData), is(notNullValue())); assertThat(arrayBasedStorageLeaf.get(defaultData), is(nullValue())); List<IStorageDescriptor> results = arrayBasedStorageLeaf.query(storageIndexQuery); assertThat(results.size(), is(equalTo(entries - 1))); for (IStorageDescriptor storageDescriptor : results) { List<IStorageDescriptor> resultsForkJoin = arrayBasedStorageLeaf.query(storageIndexQuery, forkJoinPool); assertThat(resultsForkJoin.size(), is(equalTo(entries - 1))); for (IStorageDescriptor storageDescriptor : resultsForkJoin) {
indexingTree = new ArrayBasedStorageLeaf<>();