/** * Init method. */ @BeforeMethod public void init() { MockitoAnnotations.initMocks(this); storageBranchIndexer = new StorageBranchIndexer<>(delegateIndexer, childIndexer, 1, true); }
/** * {@inheritDoc} */ @Override public IStorageBranchIndexer<E> getNewInstance() { IBranchIndexer<E> branchIndexer = null; if (sharedInstance()) { branchIndexer = delegateIndexer; } else { branchIndexer = delegateIndexer.getNewInstance(); } StorageBranchIndexer<E> storageBranchIndexer = new StorageBranchIndexer<>(branchIndexer, childIndexer, passId); return storageBranchIndexer; }
/** * {@inheritDoc} */ @Override public IStorageTreeComponent<DefaultData> getObject() throws Exception { // the time-stamp indexer has to be the last indexer in the tree, so that the amount of // files in storage won't grow with the time passing by StorageBranchIndexer<DefaultData> timestampIndexer = new StorageBranchIndexer<>(new TimestampIndexer<>(), true); StorageBranchIndexer<DefaultData> sqlStringIndexer = new StorageBranchIndexer<>(new SqlStringIndexer<>(10), timestampIndexer, false); StorageBranchIndexer<DefaultData> methodIdentIndexer = new StorageBranchIndexer<>(new MethodIdentIndexer<>(), sqlStringIndexer, false); StorageBranchIndexer<DefaultData> objectTypeIndexer = new StorageBranchIndexer<>(new ObjectTypeIndexer<>(), methodIdentIndexer, false); StorageBranchIndexer<DefaultData> invocationChildrenIndexer = new StorageBranchIndexer<>(new InvocationChildrenIndexer<>(), objectTypeIndexer, false); StorageBranchIndexer<DefaultData> platformIndexer = new StorageBranchIndexer<>(new PlatformIdentIndexer<>(), invocationChildrenIndexer, false); return new StorageBranch<>(platformIndexer); }
/** * Confirm {@link IndexingException} will be reaised when key can not be generated for element. * * @throws IndexingException */ @Test(expectedExceptions = { IndexingException.class }) public void putWithNoKey() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new TimestampIndexer<>(), false)); InvocationSequenceData invocation = mock(InvocationSequenceData.class); when(invocation.getId()).thenReturn(1L); rootBranch.put(invocation); }
/** * Test that get will work even when branch can not generate key for the element if ID is * correctly set. * * @throws IndexingException */ @Test public void getWithNoKey() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new TimestampIndexer<>(), false)); InvocationSequenceData invocation = mock(InvocationSequenceData.class); when(invocation.getId()).thenReturn(1L); when(invocation.getTimeStamp()).thenReturn(new Timestamp(new Date().getTime())); IStorageDescriptor storageDescriptor = rootBranch.put(invocation); when(invocation.getTimeStamp()).thenReturn(null); // test get assertThat(rootBranch.get(invocation), is(equalTo(storageDescriptor))); // then get and remove assertThat(rootBranch.getAndRemove(invocation), is(equalTo(storageDescriptor))); // confirm it is removed assertThat(rootBranch.get(invocation), is(nullValue())); }
/** * 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))); }
/** * Test tree with empty query. All elements should be returned. * * @throws IndexingException * If {@link IndexingException} occurs. */ @Test public void emptyQueryTest() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new ObjectTypeIndexer<>(), false)); DefaultData defaultData = mock(DefaultData.class); when(defaultData.getId()).thenReturn(1L); IStorageDescriptor storageDescriptor1 = rootBranch.put(defaultData); storageDescriptor1.setPositionAndSize(0, 1); SqlStatementData defaultData2 = mock(SqlStatementData.class); when(defaultData2.getId()).thenReturn(2L); IStorageDescriptor storageDescriptor2 = rootBranch.put(defaultData2); storageDescriptor2.setPositionAndSize(2, 1); List<IStorageDescriptor> results = rootBranch.query(storageIndexQuery); assertThat(results.size(), is(equalTo(2))); // Test for forkJoinPool List<IStorageDescriptor> resultsForkJoin = rootBranch.query(storageIndexQuery, forkJoinPool); assertThat(resultsForkJoin.size(), is(equalTo(2))); }
public void nextComponentIsBranch() { int id = 1; storageBranchIndexer = new StorageBranchIndexer<>(delegateIndexer, childIndexer, id, true); DefaultData defaultData = mock(DefaultData.class); storageBranchIndexer = new StorageBranchIndexer<>(delegateIndexer, childIndexer, id, false);
Timestamp plusHour = new Timestamp(new Date().getTime() + (25 * 60 * 1000)); IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new TimestampIndexer<>(), false));
IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new ObjectTypeIndexer<>(), false));
IStorageTreeComponent<MethodSensorData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new MethodIdentIndexer<MethodSensorData>(), false));
IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new PlatformIdentIndexer<>(), false));
StorageBranchIndexer<DefaultData> sensorTypeIndexer = new StorageBranchIndexer<>(new SensorTypeIdentIndexer<>(), false); StorageBranchIndexer<DefaultData> objectTypeIndexer = new StorageBranchIndexer<>(new ObjectTypeIndexer<>(), sensorTypeIndexer, false); StorageBranchIndexer<DefaultData> platformTypeIndexer = new StorageBranchIndexer<>(new PlatformIdentIndexer<>(), objectTypeIndexer, false); IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(platformTypeIndexer);
/** * Test that putting one element will return the same {@link IStorageDescriptor} as when get is * executed.. * * @throws IndexingException * If {@link IndexingException} occurs. */ @Test public void putAndGetInvocation() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new ObjectTypeIndexer<>(), false)); InvocationSequenceData invocationSequenceData = new InvocationSequenceData(); invocationSequenceData.setId(1L); IStorageDescriptor storageDescriptor = rootBranch.put(invocationSequenceData); assertThat(storageDescriptor, comparesEqualTo(rootBranch.get(invocationSequenceData))); }
StorageBranchIndexer<DefaultData> sensorTypeIndexer = new StorageBranchIndexer<>(new SensorTypeIdentIndexer<>(), false); StorageBranchIndexer<DefaultData> objectTypeIndexer = new StorageBranchIndexer<>(new ObjectTypeIndexer<>(), sensorTypeIndexer, false); StorageBranchIndexer<DefaultData> platformTypeIndexer = new StorageBranchIndexer<>(new PlatformIdentIndexer<>(), objectTypeIndexer, false); IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(platformTypeIndexer);