return new StorageBranch<>(childIndexer); } else { indexer.setId(id); return new StorageBranch<>(indexer);
/** * 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())); }
/** * 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); }
Timestamp plusHour = new Timestamp(new Date().getTime() + (25 * 60 * 1000)); IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new TimestampIndexer<>(), false));
/** * 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))); }
IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new ObjectTypeIndexer<>(), false));
IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new PlatformIdentIndexer<>(), false));
IStorageTreeComponent<MethodSensorData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new MethodIdentIndexer<MethodSensorData>(), 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);
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))); }
/** * {@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); }