remove unused code

This commit is contained in:
Jonathan Shook 2023-05-18 14:56:52 -05:00
parent 97cd593b3c
commit 4e6ad6db61
3 changed files with 0 additions and 247 deletions

View File

@ -1,84 +0,0 @@
/*
* Copyright (c) 2022 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.activitytype.diag;
import java.util.ArrayList;
import java.util.List;
import java.util.function.LongToIntFunction;
public class DiagOpData {
private final String description;
private final List<String> diaglog = new ArrayList<>();
private LongToIntFunction resultFunc;
private long simulatedDelayNanos;
public DiagOpData(String description) {
this.description = description;
}
/**
* If this function is provided, the result will be set to the value of the
* evaluated function with the op cycle.
*
* This is known as "resultfunc" in parameter space.
*
* The function must be thread-safe.
*
* @param resultFunc A function to map the cycle to the result value
* @return this, for method chaining
*/
public DiagOpData withResultFunction(LongToIntFunction resultFunc) {
this.resultFunc = resultFunc;
return this;
}
/**
* If this function is provided, the completion of the operation will be
* delayed until the system nanotime is at least the op start time in
* addition to the provided delay.
*
* This is controlled as "delayfunc" in parameter space.
*
* @param simulatedDelayNanos The amount of nanos ensure as a minimum
* of processing time for this op
*/
public DiagOpData setSimulatedDelayNanos(long simulatedDelayNanos) {
this.simulatedDelayNanos = simulatedDelayNanos;
return this;
}
public long getSimulatedDelayNanos() {
return simulatedDelayNanos;
}
@Override
public String toString() {
return super.toString() + ", description:'" + description;
}
public String getDescription() {
return description;
}
public void log(String logline) {
this.diaglog.add(logline);
}
public List<String> getDiagLog() {
return diaglog;
}
}

View File

@ -1,106 +0,0 @@
/*
* Copyright (c) 2022 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.activitytype.diag;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.security.InvalidParameterException;
import java.util.concurrent.atomic.AtomicLong;
public class SequenceBlocker {
private final static Logger logger = LogManager.getLogger(SequenceBlocker.class);
private final AtomicLong sequence;
private final AtomicLong waiting=new AtomicLong(0L);
private final boolean errorsAreFatal;
// private PriorityBlockingQueue<TakeANumber> queue = new PriorityBlockingQueue<>();
private Exception fatalError;
public SequenceBlocker(long start, boolean errorsAreFatal) {
this.sequence = new AtomicLong(start);
this.errorsAreFatal = errorsAreFatal;
}
public synchronized void awaitAndRun(long startAt, long endPlus, Runnable task) {
waiting.incrementAndGet();
if (fatalError != null) {
throw new RuntimeException("There was previously a fatal error, not allowing new tasks. Error=" + fatalError.getMessage());
}
// queue.add(new TakeANumber(startAt, sequencePlusCount, task));
while (sequence.get() != startAt) {
try {
wait(1_000);
} catch (InterruptedException ignored) {
}
}
try {
task.run();
} catch (Exception e) {
logger.error(() -> "Runnable errored in SequenceBlocker: " + e.getMessage());
if (errorsAreFatal) {
this.fatalError = e;
}
throw e;
} finally {
waiting.decrementAndGet();
if (!sequence.compareAndSet(startAt,endPlus)) {
throw new InvalidParameterException("Serious logic error in synchronizer. This should never fail.");
}
}
notifyAll();
}
public synchronized void awaitCompletion() {
while (waiting.get()>0)
try {
wait(60_000);
} catch (InterruptedException ignored) {
}
}
private final static class TakeANumber implements Comparable<TakeANumber> {
private final long start;
private final long endPlus;
private final Runnable task;
public TakeANumber(long start, long endPlus, Runnable task) {
this.start = start;
this.endPlus = endPlus;
this.task = task;
}
@Override
public int compareTo(TakeANumber o) {
return Long.compare(start, o.start);
}
public long getStart() {
return start;
}
public long getEndPlus() {
return endPlus;
}
public String toString() {
return "[" + getStart() + "-" + getEndPlus() + ")";
}
}
}

View File

@ -1,57 +0,0 @@
/*
* Copyright (c) 2022 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.activitytype.diag;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
public class SequenceBlockerTest {
private final static Logger logger = LogManager.getLogger(SequenceBlockerTest.class);
@Test
public void await() throws Exception {
SequenceBlocker sb = new SequenceBlocker(234L, true);
new Thread(() -> sb.awaitAndRun(249L,253L, new Printer(logger, "249-253"))).start();
Thread.sleep(100);
new Thread(() -> sb.awaitAndRun(247L,249L, new Printer(logger, "247-249"))).start();
Thread.sleep(100);
new Thread(() -> sb.awaitAndRun(234L,247L, new Printer(logger, "234-247"))).start();
sb.awaitCompletion();
System.out.flush();
}
private final static class Printer implements Runnable {
private final Logger logger;
private final String out;
public Printer(Logger logger, String out) {
this.logger = logger;
this.out = out;
}
@Override
public void run() {
logger.debug(out);
}
}
}