org.apache.lucene.util.SetOnce Java Examples
The following examples show how to use
org.apache.lucene.util.SetOnce.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportAddVotingConfigExclusionsActionTests.java From crate with Apache License 2.0 | 6 votes |
public void testReturnsErrorIfNoMatchingNodes() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); final SetOnce<TransportException> exceptionHolder = new SetOnce<>(); transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest(new String[]{"not-a-node"}), expectError(e -> { exceptionHolder.set(e); countDownLatch.countDown(); }) ); assertTrue(countDownLatch.await(30, TimeUnit.SECONDS)); final Throwable rootCause = exceptionHolder.get().getRootCause(); assertThat(rootCause, instanceOf(IllegalArgumentException.class)); assertThat(rootCause.getMessage(), equalTo("add voting config exclusions request for [not-a-node] matched no master-eligible nodes")); }
Example #2
Source File: TransportAddVotingConfigExclusionsActionTests.java From crate with Apache License 2.0 | 6 votes |
public void testOnlyMatchesMasterEligibleNodes() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); final SetOnce<TransportException> exceptionHolder = new SetOnce<>(); transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest(new String[]{"_all", "master:false"}), expectError(e -> { exceptionHolder.set(e); countDownLatch.countDown(); }) ); assertTrue(countDownLatch.await(30, TimeUnit.SECONDS)); final Throwable rootCause = exceptionHolder.get().getRootCause(); assertThat(rootCause, instanceOf(IllegalArgumentException.class)); assertThat(rootCause.getMessage(), equalTo("add voting config exclusions request for [_all, master:false] matched no master-eligible nodes")); }
Example #3
Source File: TransportAddVotingConfigExclusionsActionTests.java From crate with Apache License 2.0 | 6 votes |
public void testTimesOut() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); final SetOnce<TransportException> exceptionHolder = new SetOnce<>(); transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest(new String[]{"other1"}, TimeValue.timeValueMillis(100)), expectError(e -> { exceptionHolder.set(e); countDownLatch.countDown(); }) ); assertTrue(countDownLatch.await(30, TimeUnit.SECONDS)); final Throwable rootCause = exceptionHolder.get().getRootCause(); assertThat(rootCause,instanceOf(ElasticsearchTimeoutException.class)); assertThat(rootCause.getMessage(), startsWith("timed out waiting for voting config exclusions [{other1}")); }
Example #4
Source File: TransportClearVotingConfigExclusionsActionTests.java From crate with Apache License 2.0 | 6 votes |
public void testClearsVotingConfigExclusions() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); final SetOnce<ClearVotingConfigExclusionsResponse> responseHolder = new SetOnce<>(); final ClearVotingConfigExclusionsRequest clearVotingConfigExclusionsRequest = new ClearVotingConfigExclusionsRequest(); clearVotingConfigExclusionsRequest.setWaitForRemoval(false); transportService.sendRequest(localNode, ClearVotingConfigExclusionsAction.NAME, clearVotingConfigExclusionsRequest, expectSuccess(r -> { responseHolder.set(r); countDownLatch.countDown(); }) ); assertTrue(countDownLatch.await(30, TimeUnit.SECONDS)); assertNotNull(responseHolder.get()); assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), empty()); }
Example #5
Source File: TransportClearVotingConfigExclusionsActionTests.java From crate with Apache License 2.0 | 6 votes |
public void testTimesOutIfWaitingForNodesThatAreNotRemoved() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); final SetOnce<TransportException> responseHolder = new SetOnce<>(); final ClearVotingConfigExclusionsRequest clearVotingConfigExclusionsRequest = new ClearVotingConfigExclusionsRequest(); clearVotingConfigExclusionsRequest.setTimeout(TimeValue.timeValueMillis(100)); transportService.sendRequest(localNode, ClearVotingConfigExclusionsAction.NAME, clearVotingConfigExclusionsRequest, expectError(e -> { responseHolder.set(e); countDownLatch.countDown(); }) ); assertTrue(countDownLatch.await(30, TimeUnit.SECONDS)); assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), containsInAnyOrder(otherNode1Exclusion, otherNode2Exclusion)); final Throwable rootCause = responseHolder.get().getRootCause(); assertThat(rootCause, instanceOf(ElasticsearchTimeoutException.class)); assertThat(rootCause.getMessage(), startsWith("timed out waiting for removal of nodes; if nodes should not be removed, set waitForRemoval to false. [")); }
Example #6
Source File: TransportClearVotingConfigExclusionsActionTests.java From crate with Apache License 2.0 | 6 votes |
public void testSucceedsIfNodesAreRemovedWhileWaiting() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); final SetOnce<ClearVotingConfigExclusionsResponse> responseHolder = new SetOnce<>(); transportService.sendRequest(localNode, ClearVotingConfigExclusionsAction.NAME, new ClearVotingConfigExclusionsRequest(), expectSuccess(r -> { responseHolder.set(r); countDownLatch.countDown(); }) ); final ClusterState.Builder builder = builder(clusterService.state()); builder.nodes(DiscoveryNodes.builder(clusterService.state().nodes()).remove(otherNode1).remove(otherNode2)); setState(clusterService, builder); assertTrue(countDownLatch.await(30, TimeUnit.SECONDS)); assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), empty()); }
Example #7
Source File: TestIndexWriter.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testMergeAllDeleted() throws IOException { Directory dir = newDirectory(); IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())); AtomicBoolean keepFullyDeletedSegments = new AtomicBoolean(); iwc.setMergePolicy(new FilterMergePolicy(iwc.getMergePolicy()) { @Override public boolean keepFullyDeletedSegment(IOSupplier<CodecReader> readerIOSupplier) throws IOException { return keepFullyDeletedSegments.get(); } }); final SetOnce<IndexWriter> iwRef = new SetOnce<>(); IndexWriter evilWriter = RandomIndexWriter.mockIndexWriter(random(), dir, iwc, new RandomIndexWriter.TestPoint() { @Override public void apply(String message) { if ("startCommitMerge".equals(message)) { keepFullyDeletedSegments.set(false); } else if ("startMergeInit".equals(message)) { keepFullyDeletedSegments.set(true); } } }); iwRef.set(evilWriter); for (int i = 0; i < 1000; i++) { addDoc(evilWriter); if (random().nextInt(17) == 0) { evilWriter.commit(); } } evilWriter.deleteDocuments(new MatchAllDocsQuery()); evilWriter.forceMerge(1); evilWriter.close(); dir.close(); }
Example #8
Source File: TestIndexWriter.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testMergeZeroDocsMergeIsClosedOnce() throws IOException { LogDocMergePolicy keepAllSegments = new LogDocMergePolicy() { @Override public boolean keepFullyDeletedSegment(IOSupplier<CodecReader> readerIOSupplier) { return true; } }; try (Directory dir = newDirectory()) { try (IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig().setMergePolicy(new OneMergeWrappingMergePolicy(keepAllSegments, merge -> { SetOnce<Boolean> onlyFinishOnce = new SetOnce<>(); return new MergePolicy.OneMerge(merge.segments) { @Override public void mergeFinished(boolean success, boolean segmentDropped) throws IOException { super.mergeFinished(success, segmentDropped); onlyFinishOnce.set(true); } }; })))) { Document doc = new Document(); doc.add(new StringField("id", "1", Field.Store.NO)); writer.addDocument(doc); writer.flush(); writer.addDocument(doc); writer.flush(); writer.deleteDocuments(new Term("id", "1")); writer.flush(); assertEquals(2, writer.getSegmentCount()); assertEquals(0, writer.getDocStats().numDocs); assertEquals(2, writer.getDocStats().maxDoc); writer.forceMerge(1); } } }
Example #9
Source File: SnapshotRestoreIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
private RepositoryData getRepositoryData() throws Exception { RepositoriesService service = internalCluster().getInstance(RepositoriesService.class, internalCluster().getMasterName()); Repository repository = service.repository(REPOSITORY_NAME); ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class, internalCluster().getMasterName()); final SetOnce<RepositoryData> repositoryData = new SetOnce<>(); final CountDownLatch latch = new CountDownLatch(1); threadPool.executor(ThreadPool.Names.SNAPSHOT).execute(() -> { repositoryData.set(repository.getRepositoryData()); latch.countDown(); }); latch.await(); return repositoryData.get(); }
Example #10
Source File: TransportRequestDeduplicatorTests.java From crate with Apache License 2.0 | 4 votes |
@Test public void testRequestDeduplication() throws Exception { AtomicInteger successCount = new AtomicInteger(); AtomicInteger failureCount = new AtomicInteger(); Exception failure = randomBoolean() ? new TransportException("simulated") : null; final TransportRequest request = new TransportRequest() { @Override public void setParentTask(final TaskId taskId) { } }; final TransportRequestDeduplicator<TransportRequest> deduplicator = new TransportRequestDeduplicator<>(); final SetOnce<ActionListener<Void>> listenerHolder = new SetOnce<>(); int iterationsPerThread = scaledRandomIntBetween(100, 1000); Thread[] threads = new Thread[between(1, 4)]; Phaser barrier = new Phaser(threads.length + 1); for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(() -> { barrier.arriveAndAwaitAdvance(); for (int n = 0; n < iterationsPerThread; n++) { deduplicator.executeOnce(request, new ActionListener<Void>() { @Override public void onResponse(Void aVoid) { successCount.incrementAndGet(); } @Override public void onFailure(Exception e) { assertThat(e, sameInstance(failure)); failureCount.incrementAndGet(); } }, (req, reqListener) -> listenerHolder.set(reqListener)); } }); threads[i].start(); } barrier.arriveAndAwaitAdvance(); for (Thread t : threads) { t.join(); } final ActionListener<Void> listener = listenerHolder.get(); assertThat(deduplicator.size(), equalTo(1)); if (failure != null) { listener.onFailure(failure); } else { listener.onResponse(null); } assertThat(deduplicator.size(), equalTo(0)); assertBusy(() -> { if (failure != null) { assertThat(successCount.get(), equalTo(0)); assertThat(failureCount.get(), equalTo(threads.length * iterationsPerThread)); } else { assertThat(successCount.get(), equalTo(threads.length * iterationsPerThread)); assertThat(failureCount.get(), equalTo(0)); } }); }