List of usage examples for org.apache.cassandra.utils.progress ProgressEventType SUCCESS
ProgressEventType SUCCESS
To view the source code for org.apache.cassandra.utils.progress ProgressEventType SUCCESS.
Click Source Link
From source file:io.cassandrareaper.service.RepairRunnerTest.java
License:Apache License
@Test public void testHangingRepairNewAPI() throws InterruptedException, ReaperException { final String CLUSTER_NAME = "reaper"; final String KS_NAME = "reaper"; final Set<String> CF_NAMES = Sets.newHashSet("reaper"); final boolean INCREMENTAL_REPAIR = false; final Set<String> NODES = Sets.newHashSet("127.0.0.1"); final Set<String> DATACENTERS = Collections.emptySet(); final Set<String> BLACKLISTED_TABLES = Collections.emptySet(); final long TIME_RUN = 41L; final double INTENSITY = 0.5f; final int REPAIR_THREAD_COUNT = 1; final IStorage storage = new MemoryStorage(); storage.addCluster(new Cluster(CLUSTER_NAME, null, Collections.<String>singleton("127.0.0.1"))); RepairUnit cf = storage.addRepairUnit(new RepairUnit.Builder(CLUSTER_NAME, KS_NAME, CF_NAMES, INCREMENTAL_REPAIR, NODES, DATACENTERS, BLACKLISTED_TABLES, REPAIR_THREAD_COUNT)); DateTimeUtils.setCurrentMillisFixed(TIME_RUN); RepairRun run = storage.addRepairRun( new RepairRun.Builder(CLUSTER_NAME, cf.getId(), DateTime.now(), INTENSITY, 1, RepairParallelism.PARALLEL), Collections.singleton(RepairSegment.builder( Segment.builder().withTokenRange(new RingRange(BigInteger.ZERO, BigInteger.ONE)).build(), cf.getId())));/*from www . j a va2 s .c o m*/ final UUID RUN_ID = run.getId(); final UUID SEGMENT_ID = storage.getNextFreeSegmentInRange(run.getId(), Optional.absent()).get().getId(); assertEquals(storage.getRepairSegment(RUN_ID, SEGMENT_ID).get().getState(), RepairSegment.State.NOT_STARTED); AppContext context = new AppContext(); context.storage = storage; context.config = new ReaperApplicationConfiguration(); context.repairManager = RepairManager.create(context); context.repairManager.initializeThreadPool(1, 500, TimeUnit.MILLISECONDS, 1, TimeUnit.MILLISECONDS); final Semaphore mutex = new Semaphore(0); context.jmxConnectionFactory = new JmxConnectionFactory() { final AtomicInteger repairAttempts = new AtomicInteger(1); @Override protected JmxProxy connect(final Optional<RepairStatusHandler> handler, Node host, int connectionTimeout) throws ReaperException { final JmxProxy jmx = mock(JmxProxy.class); when(jmx.getClusterName()).thenReturn(CLUSTER_NAME); when(jmx.isConnectionAlive()).thenReturn(true); when(jmx.tokenRangeToEndpoint(anyString(), any(Segment.class))).thenReturn(Lists.newArrayList("")); when(jmx.getRangeToEndpointMap(anyString())).thenReturn(RepairRunnerTest.sixNodeCluster()); when(jmx.getDataCenter()).thenReturn("dc1"); when(jmx.getDataCenter(anyString())).thenReturn("dc1"); //doNothing().when(jmx).cancelAllRepairs(); when(jmx.triggerRepair(any(BigInteger.class), any(BigInteger.class), any(), any(RepairParallelism.class), any(), anyBoolean(), any(), any(), any(), any(Integer.class))) .then((invocation) -> { assertEquals(RepairSegment.State.NOT_STARTED, storage.getRepairSegment(RUN_ID, SEGMENT_ID).get().getState()); final int repairNumber = repairAttempts.getAndIncrement(); switch (repairNumber) { case 1: new Thread() { @Override public void run() { handler.get().handle(repairNumber, Optional.absent(), Optional.of(ProgressEventType.START), null, jmx); assertEquals(RepairSegment.State.RUNNING, storage .getRepairSegment(RUN_ID, SEGMENT_ID).get().getState()); } }.start(); break; case 2: new Thread() { @Override public void run() { handler.get().handle(repairNumber, Optional.absent(), Optional.of(ProgressEventType.START), null, jmx); assertEquals(RepairSegment.State.RUNNING, storage .getRepairSegment(RUN_ID, SEGMENT_ID).get().getState()); handler.get().handle(repairNumber, Optional.absent(), Optional.of(ProgressEventType.SUCCESS), null, jmx); assertEquals(RepairSegment.State.DONE, storage .getRepairSegment(RUN_ID, SEGMENT_ID).get().getState()); handler.get().handle(repairNumber, Optional.absent(), Optional.of(ProgressEventType.COMPLETE), null, jmx); mutex.release(); LOG.info("MUTEX RELEASED"); } }.start(); break; default: fail("triggerRepair should only have been called twice"); } return repairNumber; }); return jmx; } }; context.repairManager.startRepairRun(run); await().with().atMost(20, TimeUnit.SECONDS).until(() -> { try { mutex.acquire(); LOG.info("MUTEX ACQUIRED"); // TODO: refactor so that we can properly wait for the repair runner to finish rather than // TODO: using this sleep(). Thread.sleep(1000); return true; } catch (InterruptedException ex) { throw new IllegalStateException(ex); } }); assertEquals(RepairRun.RunState.DONE, storage.getRepairRun(RUN_ID).get().getRunState()); }