BTreeIndex implements Index { @Override public void configure(Configuration configuration) throws ConfigurationException { pageSize = configuration.getAttribute(PAGE_SIZE_CONF, DEFAULT_PAGE_SIZE); } BTreeIndex(File indexLocation, KeyInfo keyInfo); @Override void configure(Configuration configuration); @Override boolean hasUniqueConstraint(); @Override KeyInfo getKeyInfo(); @Override String getName(); @Override long count(); @Override int getPageSize(); @Override int getIndexType(); @Override int match(Set<String> fields); @Override IndexSearchResultIteratorCollection searchIndex(SearchCondition searchCondition, SearchLimit searchLimit); @Override IndexIterator getIndexIterator(); @Override void insertIntoIndex(Key key); @Override void removeFromIndex(Key key); @Override void updateKey(Key oldKey, Key newKey); @Override void openIndex(); @Override void close(); @Override void removeIndex(); @Override void flushIndex(); @Override IndexScanReport scan(ScanIntent intent, Iterator<IndexableItem> indexableItems); @Override void rebuildIndex(Iterator<IndexableItem> indexableItems); @Override MemoryAware getMemoryManager(); @Override IndexState getState(); @Override String toString();  }
@Test public void testConcurrentInsert() throws Exception { int nrThreads = 20; int nrRecords = 10000; Map<String, String> p = new HashMap<>(); p.put("MaxMemory", "32m"); GlobalCachingMemoryManager.getGlobalInstance().configure(new ManualConfiguration("Caching", p)); KeyInfo keyInfo = new KeyInfoImpl(new SimpleIndexField("somekey", new StringKeyType()), new SimpleIndexField("RECORD_POINTER", new LongKeyType())); try (BTreeIndex index = new BTreeIndex(new File(tmpDir, "indexbag_somekey.idx"), keyInfo)) { Map<Thread, BTreeIndexWriterThread> writers = new HashMap<>(); for (int i = 0; i < nrThreads; i++) { BTreeIndexWriterThread writer = new BTreeIndexWriterThread(index, i * nrRecords, nrRecords); Thread writerThread = new Thread(writer, "WriterThread" + i); writers.put(writerThread, writer); } for (Thread thread : writers.keySet()) { thread.start(); } for (Map.Entry<Thread, BTreeIndexWriterThread> writerEntry : writers.entrySet()) { writerEntry.getKey().join(); BTreeIndexWriterThread writer = writerEntry.getValue(); LOG.info("Average time: {} ({} ms.)", writer.getAverage(), (double) writer.getAverage() / (double) (1000 * 1000)); Assert.assertEquals("Expected no failures in insert operation", 0, writer.getFailures()); } LOG.info("Using: {} bytes", GlobalCachingMemoryManager.getGlobalInstance().calculateMemorySize()); LOG.info("Used memory: {}", Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); } }