Example usage for org.apache.commons.io FileUtils ONE_MB

List of usage examples for org.apache.commons.io FileUtils ONE_MB

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils ONE_MB.

Prototype

long ONE_MB

To view the source code for org.apache.commons.io FileUtils ONE_MB.

Click Source Link

Document

The number of bytes in a megabyte.

Usage

From source file:org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore.java

public DataStoreBlobStore(DataStore delegate, boolean encodeLengthInId, int cacheSizeInMB) {
    this.delegate = delegate;
    this.encodeLengthInId = encodeLengthInId;

    long cacheSize = (long) cacheSizeInMB * FileUtils.ONE_MB;
    this.cache = CacheLIRS.<String, byte[]>newBuilder().module(MEM_CACHE_NAME).recordStats()
            .maximumWeight(cacheSize).weigher(weigher).build();
    this.cacheStats = new CacheStats(cache, MEM_CACHE_NAME, weigher, cacheSize);
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCacheTest.java

@Test
public void cacheEnabled() throws Exception {
    ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100);
    assertNotNull(cache.getCacheStats());

    Blob b = new IdBlob("hello", "a");
    String text = cache.get("/a", "foo", b, false);
    assertNull(text);/*from   w  ww.j  av a 2  s  .c  o  m*/

    cache.put(b, new ExtractedText(ExtractionResult.SUCCESS, "test hello"));

    text = cache.get("/a", "foo", b, false);
    assertEquals("test hello", text);
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCacheTest.java

@Test
public void cacheEnabledNonIdBlob() throws Exception {
    ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100);

    Blob b = new ArrayBasedBlob("hello".getBytes());
    String text = cache.get("/a", "foo", b, false);
    assertNull(text);//from   w w  w. j  a  v  a 2s  .c  o m

    cache.put(b, new ExtractedText(ExtractionResult.SUCCESS, "test hello"));

    text = cache.get("/a", "foo", b, false);
    assertNull(text);
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCacheTest.java

@Test
public void cacheEnabledErrorInTextExtraction() throws Exception {
    ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100);

    Blob b = new IdBlob("hello", "a");
    String text = cache.get("/a", "foo", b, false);
    assertNull(text);/*from  w w  w . j  a  va2  s.c  o  m*/

    cache.put(b, new ExtractedText(ExtractionResult.ERROR, "test hello"));

    text = cache.get("/a", "foo", b, false);
    assertNull(text);
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCacheTest.java

@Test
public void preExtractionNoReindexNoProvider() throws Exception {
    ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100);

    Blob b = new IdBlob("hello", "a");
    String text = cache.get("/a", "foo", b, true);
    assertNull(text);//  w  ww  .j ava 2 s .  c o m
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCacheTest.java

@Test
public void preExtractionNoReindex() throws Exception {
    ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100);
    PreExtractedTextProvider provider = mock(PreExtractedTextProvider.class);

    cache.setExtractedTextProvider(provider);
    Blob b = new IdBlob("hello", "a");
    String text = cache.get("/a", "foo", b, false);
    assertNull(text);/* w  w  w  .  j av a2 s.  c o  m*/

    verifyZeroInteractions(provider);
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCacheTest.java

@Test
public void preExtractionReindex() throws Exception {
    ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100);
    PreExtractedTextProvider provider = mock(PreExtractedTextProvider.class);

    cache.setExtractedTextProvider(provider);
    when(provider.getText(anyString(), any(Blob.class)))
            .thenReturn(new ExtractedText(ExtractionResult.SUCCESS, "bar"));
    Blob b = new IdBlob("hello", "a");
    String text = cache.get("/a", "foo", b, true);
    assertEquals("bar", text);
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.ExtractedTextCacheTest.java

@Test
public void preExtractionAlwaysUse() throws Exception {
    ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100, true);
    PreExtractedTextProvider provider = mock(PreExtractedTextProvider.class);

    cache.setExtractedTextProvider(provider);
    when(provider.getText(anyString(), any(Blob.class)))
            .thenReturn(new ExtractedText(ExtractionResult.SUCCESS, "bar"));
    Blob b = new IdBlob("hello", "a");
    String text = cache.get("/a", "foo", b, false);
    assertEquals("bar", text);
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProviderServiceTest.java

@Test
public void enableExtractedTextCaching() throws Exception {
    Map<String, Object> config = getDefaultConfig();
    config.put("extractedTextCacheSizeInMB", 11);
    MockOsgi.activate(service, context.bundleContext(), config);

    ExtractedTextCache textCache = service.getExtractedTextCache();
    assertNotNull(textCache.getCacheStats());
    assertNotNull(context.getService(CacheStatsMBean.class));

    assertEquals(11 * FileUtils.ONE_MB, textCache.getCacheStats().getMaxTotalWeight());

    MockOsgi.deactivate(service);//from  w  ww  . j  av  a  2  s  .  c om

    assertNull(context.getService(CacheStatsMBean.class));
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LucenePropertyIndexTest.java

@Override
protected ContentRepository createRepository() {
    IndexCopier copier = createIndexCopier();
    editorProvider = new LuceneIndexEditorProvider(copier, new ExtractedTextCache(10 * FileUtils.ONE_MB, 100));
    LuceneIndexProvider provider = new LuceneIndexProvider(copier);
    nodeStore = new MemoryNodeStore();
    return new Oak(nodeStore).with(new InitialContent()).with(new OpenSecurityProvider())
            .with((QueryIndexProvider) provider).with((Observer) provider).with(editorProvider)
            .with(new PropertyIndexEditorProvider()).with(new NodeTypeIndexProvider())
            .createContentRepository();/*from w  w  w.j a v a 2  s . com*/
}