当前位置: 首页>>代码示例>>Java>>正文


Java ByteSizeUnit类代码示例

本文整理汇总了Java中org.elasticsearch.common.unit.ByteSizeUnit的典型用法代码示例。如果您正苦于以下问题:Java ByteSizeUnit类的具体用法?Java ByteSizeUnit怎么用?Java ByteSizeUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ByteSizeUnit类属于org.elasticsearch.common.unit包,在下文中一共展示了ByteSizeUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setRandomIndexTranslogSettings

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
private static Settings.Builder setRandomIndexTranslogSettings(Random random, Settings.Builder builder) {
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(RandomNumbers.randomIntBetween(random, 1, 300), ByteSizeUnit.MB));
    }
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(1, ByteSizeUnit.PB)); // just don't flush
    }
    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), RandomPicks.randomFrom(random, Translog.Durability.values()));
    }

    if (random.nextBoolean()) {
        builder.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), RandomNumbers.randomIntBetween(random, 100, 5000), TimeUnit.MILLISECONDS);
    }

    return builder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:ESIntegTestCase.java

示例2: testMaxSizeExceededOnNew

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
public void testMaxSizeExceededOnNew() throws Exception {
    final int size = scaledRandomIntBetween(5, 1 << 22);
    for (String type : Arrays.asList("Byte", "Int", "Long", "Float", "Double", "Object")) {
        HierarchyCircuitBreakerService hcbs = new HierarchyCircuitBreakerService(
                Settings.builder()
                        .put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), size - 1, ByteSizeUnit.BYTES)
                        .build(),
                new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
        BigArrays bigArrays = new BigArrays(null, hcbs, false).withCircuitBreaking();
        Method create = BigArrays.class.getMethod("new" + type + "Array", long.class);
        try {
            create.invoke(bigArrays, size);
            fail("expected an exception on " + create);
        } catch (InvocationTargetException e) {
            assertTrue(e.getCause() instanceof CircuitBreakingException);
        }
        assertEquals(0, hcbs.getBreaker(CircuitBreaker.REQUEST).getUsed());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:BigArraysTests.java

示例3: testSnapshotName

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
public void testSnapshotName() throws Exception {
    final Client client = client();

    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo")
            .setType("fs").setSettings(Settings.builder()
                    .put("location", randomRepoPath())
                    .put("compress", randomBoolean())
                    .put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));

    expectThrows(InvalidSnapshotNameException.class,
                 () -> client.admin().cluster().prepareCreateSnapshot("test-repo", "_foo").get());
    expectThrows(SnapshotMissingException.class,
                 () -> client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("_foo").get());
    expectThrows(SnapshotMissingException.class,
                 () -> client.admin().cluster().prepareDeleteSnapshot("test-repo", "_foo").get());
    expectThrows(SnapshotMissingException.class,
                 () -> client.admin().cluster().prepareSnapshotStatus("test-repo").setSnapshots("_foo").get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:SharedClusterSnapshotRestoreIT.java

示例4: testThatBulkProcessorCountIsCorrect

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
public void testThatBulkProcessorCountIsCorrect() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    BulkProcessorTestListener listener = new BulkProcessorTestListener(latch);

    int numDocs = randomIntBetween(10, 100);
    try (BulkProcessor processor = BulkProcessor.builder(client(), listener).setName("foo")
            //let's make sure that the bulk action limit trips, one single execution will index all the documents
            .setConcurrentRequests(randomIntBetween(0, 1)).setBulkActions(numDocs)
            .setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB))
            .build()) {

        MultiGetRequestBuilder multiGetRequestBuilder = indexDocs(client(), processor, numDocs);

        latch.await();

        assertThat(listener.beforeCounts.get(), equalTo(1));
        assertThat(listener.afterCounts.get(), equalTo(1));
        assertThat(listener.bulkFailures.size(), equalTo(0));
        assertResponseItems(listener.bulkItems, numDocs);
        assertMultiGetResponse(multiGetRequestBuilder.get(), numDocs);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:BulkProcessorIT.java

示例5: testBulkProcessorFlush

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
public void testBulkProcessorFlush() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    BulkProcessorTestListener listener = new BulkProcessorTestListener(latch);

    int numDocs = randomIntBetween(10, 100);

    try (BulkProcessor processor = BulkProcessor.builder(client(), listener).setName("foo")
            //let's make sure that this bulk won't be automatically flushed
            .setConcurrentRequests(randomIntBetween(0, 10)).setBulkActions(numDocs + randomIntBetween(1, 100))
            .setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB)).build()) {

        MultiGetRequestBuilder multiGetRequestBuilder = indexDocs(client(), processor, numDocs);

        assertThat(latch.await(randomInt(500), TimeUnit.MILLISECONDS), equalTo(false));
        //we really need an explicit flush as none of the bulk thresholds was reached
        processor.flush();
        latch.await();

        assertThat(listener.beforeCounts.get(), equalTo(1));
        assertThat(listener.afterCounts.get(), equalTo(1));
        assertThat(listener.bulkFailures.size(), equalTo(0));
        assertResponseItems(listener.bulkItems, numDocs);
        assertMultiGetResponse(multiGetRequestBuilder.get(), numDocs);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:BulkProcessorIT.java

示例6: testNonExistingRepo_23

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
/**
 * Test case for issue #23: https://github.com/elastic/elasticsearch-cloud-azure/issues/23
 */
public void testNonExistingRepo_23() {
    Client client = client();
    logger.info("-->  creating azure repository with path [{}]", getRepositoryPath());
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo")
            .setType("azure").setSettings(Settings.builder()
                    .put(Repository.CONTAINER_SETTING.getKey(), getContainerName())
                    .put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath())
                    .put(Repository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)
            ).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));

    logger.info("--> restore non existing snapshot");
    try {
        client.admin().cluster().prepareRestoreSnapshot("test-repo", "no-existing-snapshot").setWaitForCompletion(true).get();
        fail("Shouldn't be here");
    } catch (SnapshotMissingException ex) {
        // Expected
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:AzureSnapshotRestoreTests.java

示例7: testChunkSize

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
public void testChunkSize() throws StorageException, IOException, URISyntaxException {
    // default chunk size
    AzureRepository azureRepository = azureRepository(Settings.EMPTY);
    assertEquals(AzureStorageService.MAX_CHUNK_SIZE, azureRepository.chunkSize());

    // chunk size in settings
    int size = randomIntBetween(1, 64);
    azureRepository = azureRepository(Settings.builder().put("chunk_size", size + "mb").build());
    assertEquals(new ByteSizeValue(size, ByteSizeUnit.MB), azureRepository.chunkSize());

    // zero bytes is not allowed
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () ->
        azureRepository(Settings.builder().put("chunk_size", "0").build()));
    assertEquals("Failed to parse value [0] for setting [chunk_size] must be >= 1b", e.getMessage());

    // negative bytes not allowed
    e = expectThrows(IllegalArgumentException.class, () ->
        azureRepository(Settings.builder().put("chunk_size", "-1").build()));
    assertEquals("Failed to parse value [-1] for setting [chunk_size] must be >= 1b", e.getMessage());

    // greater than max chunk size not allowed
    e = expectThrows(IllegalArgumentException.class, () ->
        azureRepository(Settings.builder().put("chunk_size", "65mb").build()));
    assertEquals("Failed to parse value [65mb] for setting [chunk_size] must be <= 64mb", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:AzureRepositorySettingsTests.java

示例8: TranslogService

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
@Inject
public TranslogService(ShardId shardId, IndexSettingsService indexSettingsService, ThreadPool threadPool, IndexShard indexShard) {
    super(shardId, indexSettingsService.getSettings());
    this.threadPool = threadPool;
    this.indexSettingsService = indexSettingsService;
    this.indexShard = indexShard;
    this.flushThresholdOperations = indexSettings.getAsInt(INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, indexSettings.getAsInt("index.translog.flush_threshold", 50000));
    this.flushThresholdSize = indexSettings.getAsBytesSize(INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, new ByteSizeValue(100, ByteSizeUnit.MB));
    this.flushThresholdPeriod = indexSettings.getAsTime(INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD, TimeValue.timeValueMinutes(10));
    this.interval = indexSettings.getAsTime(INDEX_TRANSLOG_FLUSH_INTERVAL, timeValueMillis(5000));
    this.disableFlush = indexSettings.getAsBoolean(INDEX_TRANSLOG_DISABLE_FLUSH, false);
    logger.debug("interval [{}], flush_threshold_ops [{}], flush_threshold_size [{}], flush_threshold_period [{}]", interval, flushThresholdOperations, flushThresholdSize, flushThresholdPeriod);

    this.future = threadPool.schedule(interval, ThreadPool.Names.SAME, new TranslogBasedFlush());

    indexSettingsService.addListener(applySettings);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:TranslogService.java

示例9: custom_values_set_when_custom_values_set_for_builder

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
@Test
public void custom_values_set_when_custom_values_set_for_builder() {

    // Build:
    BulkProcessingOptions options = new BulkProcessingOptionsBuilder()
            .setName("Test")
            .setConcurrentRequests(3)
            .setBulkActions(10)
            .setBulkSize(new ByteSizeValue(2, ByteSizeUnit.MB))
            .setFlushInterval(new TimeValue(321))
            .setBackoffPolicy(BackoffPolicy.noBackoff())
            .build();

    // Check Values:
    Assert.assertEquals("Test", options.getName());
    Assert.assertEquals(3, options.getConcurrentRequests());
    Assert.assertEquals(10, options.getBulkActions());
    Assert.assertEquals(new ByteSizeValue(2, ByteSizeUnit.MB).bytes(), options.getBulkSize().bytes());
    Assert.assertEquals(new TimeValue(321).getMillis(), options.getFlushInterval().getMillis());
    Assert.assertEquals(BackoffPolicy.noBackoff().getClass(), options.getBackoffPolicy().getClass());
}
 
开发者ID:bytefish,项目名称:ElasticUtils,代码行数:22,代码来源:BulkProcessingOptionsBuilderTest.java

示例10: setRandomTranslogSettings

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
private static ImmutableSettings.Builder setRandomTranslogSettings(final Random random, final ImmutableSettings.Builder builder) {
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_OPS, RandomInts.randomIntBetween(random, 1, 10000));
    }
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE, new ByteSizeValue(RandomInts.randomIntBetween(random, 1, 300),
                ByteSizeUnit.MB));
    }
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_THRESHOLD_PERIOD,
                TimeValue.timeValueMinutes(RandomInts.randomIntBetween(random, 1, 60)));
    }
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_FLUSH_INTERVAL,
                TimeValue.timeValueMillis(RandomInts.randomIntBetween(random, 1, 10000)));
    }
    if (random.nextBoolean()) {
        builder.put(TranslogService.INDEX_TRANSLOG_DISABLE_FLUSH, random.nextBoolean());
    }
    return builder;
}
 
开发者ID:salyh,项目名称:elasticsearch-sample-plugin-audit,代码行数:22,代码来源:ElasticsearchIntegrationTest.java

示例11: execute

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
private void execute(DocumentFactory<String> factory, InsertProperties properties, int from) throws InterruptedException {
	final int threads = properties.getNumOfThreads();
	ExecutorService service = Executors.newFixedThreadPool(threads);
	int perThread = properties.getDocPerIteration() / threads;
	int to = 0;
	Timer.Context insert = metrics.timer("insert-total").time();
	for(int i = 0; i < threads; i++) {
		BulkProcessor bulkProcessor = BulkProcessor.builder(client, new BulkListener(metrics))
				.setBulkActions(properties.getBulkActions())
				.setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB))
				.setConcurrentRequests(properties.getBulkThreads())
				.build();
		from = to;
		to = from + perThread;
		SenderAction action = new SenderAction(metrics, properties, factory, bulkProcessor, from, to);
		service.execute(action);
	}
	service.shutdown();
	service.awaitTermination(60, TimeUnit.MINUTES);
	insert.stop();
	reporter.report();
}
 
开发者ID:kucera-jan-cz,项目名称:esBench,代码行数:23,代码来源:DocumentSenderImpl.java

示例12: getBulkProcessor

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
public BulkProcessor getBulkProcessor(Client client, BulkProcessor.Listener listener) {
  BulkProcessor.Builder builder = BulkProcessor.builder(client, listener);

  // Concurrent requests set to 0 to ensure ordering of documents is maintained in batches.
  // This also means BulkProcessor#flush() is blocking as is also required.
  builder.setConcurrentRequests(0);

  if (config.getBulkFlushMaxActions().isPresent()) {
    builder.setBulkActions(config.getBulkFlushMaxActions().get());
  }
  if (config.getBulkFlushMaxSizeMB().isPresent()) {
    builder.setBulkSize(new ByteSizeValue(config.getBulkFlushMaxSizeMB().get(), ByteSizeUnit.MB));
  }
  if (config.getBulkFlushIntervalMS().isPresent()) {
    builder.setFlushInterval(TimeValue.timeValueMillis(config.getBulkFlushIntervalMS().get()));
  }

  return builder.build();
}
 
开发者ID:apache,项目名称:samza,代码行数:20,代码来源:BulkProcessorFactory.java

示例13: testTooLargeResponse

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testTooLargeResponse() throws Exception {
    ContentTooLongException tooLong = new ContentTooLongException("too long!");
    CloseableHttpAsyncClient httpClient = mock(CloseableHttpAsyncClient.class);
    when(httpClient.<HttpResponse>execute(any(HttpAsyncRequestProducer.class), any(HttpAsyncResponseConsumer.class),
            any(HttpClientContext.class), any(FutureCallback.class))).then(new Answer<Future<HttpResponse>>() {
        @Override
        public Future<HttpResponse> answer(InvocationOnMock invocationOnMock) throws Throwable {
            HeapBufferedAsyncResponseConsumer consumer = (HeapBufferedAsyncResponseConsumer) invocationOnMock.getArguments()[1];
            FutureCallback callback = (FutureCallback) invocationOnMock.getArguments()[3];
            assertEquals(new ByteSizeValue(100, ByteSizeUnit.MB).bytesAsInt(), consumer.getBufferLimit());
            callback.failed(tooLong);
            return null;
        }
    });
    RemoteScrollableHitSource source = sourceWithMockedClient(true, httpClient);

    AtomicBoolean called = new AtomicBoolean();
    Consumer<Response> checkResponse = r -> called.set(true);
    Throwable e = expectThrows(RuntimeException.class,
            () -> source.doStartNextScroll(FAKE_SCROLL_ID, timeValueMillis(0), checkResponse));
    // Unwrap the some artifacts from the test
    while (e.getMessage().equals("failed")) {
        e = e.getCause();
    }
    // This next exception is what the user sees
    assertEquals("Remote responded with a chunk that was too large. Use a smaller batch size.", e.getMessage());
    // And that exception is reported as being caused by the underlying exception returned by the client
    assertSame(tooLong, e.getCause());
    assertFalse(called.get());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:RemoteScrollableHitSourceTests.java

示例14: recoverReplica

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
/**
 * Recovers a replica from the give primary, allow the user to supply a custom recovery target. A typical usage of a custom recovery
 * target is to assert things in the various stages of recovery.
 * @param replica                the recovery target shard
 * @param primary                the recovery source shard
 * @param targetSupplier         supplies an instance of {@link RecoveryTarget}
 * @param markAsRecovering       set to {@code false} if the replica is marked as recovering
 */
protected final void recoverReplica(final IndexShard replica,
                                    final IndexShard primary,
                                    final BiFunction<IndexShard, DiscoveryNode, RecoveryTarget> targetSupplier,
                                    final boolean markAsRecovering) throws IOException {
    final DiscoveryNode pNode = getFakeDiscoNode(primary.routingEntry().currentNodeId());
    final DiscoveryNode rNode = getFakeDiscoNode(replica.routingEntry().currentNodeId());
    if (markAsRecovering) {
        replica.markAsRecovering("remote", new RecoveryState(replica.routingEntry(), pNode, rNode));
    } else {
        assertEquals(replica.state(), IndexShardState.RECOVERING);
    }
    replica.prepareForIndexRecovery();
    final RecoveryTarget recoveryTarget = targetSupplier.apply(replica, pNode);

    final Store.MetadataSnapshot snapshot = getMetadataSnapshotOrEmpty(replica);
    final long startingSeqNo;
    if (snapshot.size() > 0) {
        startingSeqNo = PeerRecoveryTargetService.getStartingSeqNo(recoveryTarget);
    } else {
        startingSeqNo = SequenceNumbersService.UNASSIGNED_SEQ_NO;
    }

    final StartRecoveryRequest request =
        new StartRecoveryRequest(replica.shardId(), pNode, rNode, snapshot, false, 0, startingSeqNo);
    final RecoverySourceHandler recovery = new RecoverySourceHandler(
        primary,
        recoveryTarget,
        request,
        () -> 0L,
        e -> () -> {},
        (int) ByteSizeUnit.MB.toBytes(1),
        Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), pNode.getName()).build());
    recovery.recoverToTarget();
    recoveryTarget.markAsDone();
    replica.updateRoutingEntry(ShardRoutingHelper.moveToStarted(replica.routingEntry()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:IndexShardTestCase.java

示例15: BlobStoreRepository

import org.elasticsearch.common.unit.ByteSizeUnit; //导入依赖的package包/类
/**
 * Constructs new BlobStoreRepository
 *
 * @param metadata       The metadata for this repository including name and settings
 * @param globalSettings Settings for the node this repository object is created on
 */
protected BlobStoreRepository(RepositoryMetaData metadata, Settings globalSettings, NamedXContentRegistry namedXContentRegistry) {
    super(globalSettings);
    this.metadata = metadata;
    this.namedXContentRegistry = namedXContentRegistry;
    snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
    restoreRateLimiter = getRateLimiter(metadata.settings(), "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));
    readOnly = metadata.settings().getAsBoolean("readonly", false);

    indexShardSnapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT,
        BlobStoreIndexShardSnapshot::fromXContent, namedXContentRegistry, isCompress());
    indexShardSnapshotsFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_INDEX_CODEC, SNAPSHOT_INDEX_NAME_FORMAT,
        BlobStoreIndexShardSnapshots::fromXContent, namedXContentRegistry, isCompress());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:BlobStoreRepository.java


注:本文中的org.elasticsearch.common.unit.ByteSizeUnit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。