/** * Signals to the {@link StorageIndexingTreeHandler} that the write has failed. * <p> * Internally this method will update the {@link IStorageTreeComponent} by removing the given * {@link DefaultData} object in the write task, and remove the task from the set of tasks being * currently processed. * * @param writeTask * Write task that failed. */ public void writeFailed(WriteTask writeTask) { // get the data from the map TreeDescriptorPair treeDescriptorPair = writeTasksInProcess.get(writeTask); if (null != treeDescriptorPair) { IStorageTreeComponent<DefaultData> indexingTree = treeDescriptorPair.getIndexingTree(); // if write fails, remove the descriptor for the data from indexing tree if (null != indexingTree) { indexingTree.getAndRemove(writeTask.getData()); } } // remove the entry in map after the indexing tree was informed writeTasksInProcess.remove(writeTask); }
/** * 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())); }