本文整理汇总了Java中org.apache.commons.lang3.mutable.MutableBoolean.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java MutableBoolean.setValue方法的具体用法?Java MutableBoolean.setValue怎么用?Java MutableBoolean.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.mutable.MutableBoolean
的用法示例。
在下文中一共展示了MutableBoolean.setValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
MutableBoolean parsed = new MutableBoolean(false);
AsyncJsonParser parser = new AsyncJsonParser(root -> {
parsed.setValue(true);
try {
Assert.assertEquals(mapper.treeToValue(root, Model.class), model);
} catch (JsonProcessingException e) {
Assert.fail(e.getMessage());
}
});
for (byte b : new ObjectMapper().writeValueAsBytes(model)) {
parser.consume(new byte[] { b }, 1);
}
Assert.assertTrue(parsed.booleanValue());
}
示例2: test_chunks
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
@Test
public void test_chunks() throws IOException {
MutableBoolean parsed = new MutableBoolean(false);
AsyncJsonParser parser = new AsyncJsonParser(root -> {
parsed.setValue(true);
try {
Assert.assertEquals(mapper.treeToValue(root, Model.class), model);
} catch (JsonProcessingException e) {
Assert.fail(e.getMessage());
}
});
final int CHUNK_SIZE = 20;
byte[] bytes = new ObjectMapper().writeValueAsBytes(model);
for (int i = 0; i < bytes.length; i += CHUNK_SIZE) {
byte[] chunk = new byte[20];
int start = Math.min(bytes.length, i);
int len = Math.min(CHUNK_SIZE, bytes.length - i);
System.arraycopy(bytes, start, chunk, 0, len);
parser.consume(chunk, len);
}
Assert.assertTrue(parsed.booleanValue());
}
示例3: expiredTestBlocking
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
@Test
public void expiredTestBlocking() throws Exception
{
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
MutableBoolean queueContext = new MutableBoolean(false);
sdqqm.enqueue(query, null, queueContext);
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
sdqqm.endWindow();
sdqqm.beginWindow(1);
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
queueContext.setValue(true);
testBlocking(sdqqm);
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
sdqqm.endWindow();
sdqqm.teardown();
}
示例4: simpleExpireBlockThenUnblock
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
@Test
public void simpleExpireBlockThenUnblock() throws Exception
{
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
MutableBoolean expire = new MutableBoolean(false);
sdqqm.enqueue(query, null, expire);
sdqqm.endWindow();
sdqqm.beginWindow(1);
//Expire
expire.setValue(true);
ExceptionSaverExceptionHandler eseh = new ExceptionSaverExceptionHandler();
testBlockingNoStop(sdqqm, eseh);
query = new MockQuery("2");
sdqqm.enqueue(query, null, new MutableBoolean(false));
Thread.sleep(1000);
Assert.assertNull(eseh.getCaughtThrowable());
sdqqm.endWindow();
sdqqm.teardown();
}
示例5: handleThrowable
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
public void handleThrowable(Throwable t1, ServerName serverName,
MutableBoolean couldNotCommunicateWithServer,
MutableBoolean guaranteedClientSideOnly) throws IOException {
Throwable t2 = ClientExceptionsUtil.translatePFFE(t1);
boolean isLocalException = !(t2 instanceof RemoteException);
if ((isLocalException && ClientExceptionsUtil.isConnectionException(t2))) {
couldNotCommunicateWithServer.setValue(true);
guaranteedClientSideOnly.setValue(!(t2 instanceof CallTimeoutException));
handleFailureToServer(serverName, t2);
}
}
示例6: iterable
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
public static <T> Iterable<T> iterable(Iterator<T> seq) {
final MutableBoolean used = new MutableBoolean(false);
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
if (!used.booleanValue()) {
used.setValue(true);
return seq;
} else {
throw new IllegalStateException("only allowed to iterate this iterable once");
}
}
};
}
示例7: testLaunchTwoTopProcessesConcurrently
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
/**
* Ce test vérifie qu'il n'est pas possible de démarrer deux top-process avec maxTopConcurrent=1 de manière concurrente (= tipi va sérializer leurs exécutions)
*/
@Test
public void testLaunchTwoTopProcessesConcurrently() throws Exception {
final MutableBoolean process1Lock = new MutableBoolean(true);
datastore.put("process1Lock", process1Lock);
// on démarre le premier process
final long id1 = tipiFacade.launch(MaxTopOneJob.class, new VariableMap(
RESULTS_KEY, "testLaunchTwoTopProcessesSequentially1",
WAIT_LOCK_KEY, "process1Lock"));
// on démarre le second process
final long id2 = tipiFacade.launch(MaxTopOneJob.class, new VariableMap(
RESULTS_KEY, "testLaunchTwoTopProcessesSequentially2"));
// on laisse un peu de temps à Tipi pour tenter de démarrer le second process
Thread.sleep(2000);
Assert.assertTrue(tipiFacade.isRunning(id1)); // le premier process doit être démarré
Assert.assertTrue(tipiFacade.isRunning(id2)); // le second process doit aussi être démarré (dans le sens : une demande de démarrage a été faite)
Assert.assertTrue(tipiFacade.isProcessScheduled(id1)); // le premier process doit être en cours d'exécution
Assert.assertFalse(tipiFacade.isProcessScheduled(id2)); // le second process ne doit pas être en cours d'exécution
// on libère le lock du premier process
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (process1Lock) {
process1Lock.setValue(false);
process1Lock.notifyAll();
}
// on attend le fin d'exécution du premier process
waitWhileRunning(id1, 5000);
// on attend le fin d'exécution du second process
waitWhileRunning(id2, 5000);
// on vérifie que tout s'est bien passé pour le premier process
final Boolean runned1 = (Boolean) datastore.get("testLaunchTwoTopProcessesSequentially1");
Assert.assertTrue(runned1);
// on vérifie que tout s'est bien passé pour le second process
final Boolean runned2 = (Boolean) datastore.get("testLaunchTwoTopProcessesSequentially2");
Assert.assertTrue(runned2);
}
示例8: test
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
@Test
public void test() throws IOException, InterruptedException {
final HRegionServer rs = testUtil.getRSForFirstRegionInTable(tableName);
final HRegion region = (HRegion) rs.getRegions(tableName).get(0);
HRegion spiedRegion = spy(region);
final MutableBoolean flushed = new MutableBoolean(false);
final MutableBoolean reported = new MutableBoolean(false);
doAnswer(new Answer<FlushResult>() {
@Override
public FlushResult answer(InvocationOnMock invocation) throws Throwable {
synchronized (flushed) {
flushed.setValue(true);
flushed.notifyAll();
}
synchronized (reported) {
while (!reported.booleanValue()) {
reported.wait();
}
}
rs.getWAL(region.getRegionInfo()).abortCacheFlush(
region.getRegionInfo().getEncodedNameAsBytes());
throw new DroppedSnapshotException("testcase");
}
}).when(spiedRegion).internalFlushCacheAndCommit(Matchers.<WAL> any(),
Matchers.<MonitoredTask> any(), Matchers.<PrepareFlushResult> any(),
Matchers.<Collection<HStore>> any());
// Find region key; don't pick up key for hbase:meta by mistake.
String key = null;
for (Map.Entry<String, HRegion> entry: rs.onlineRegions.entrySet()) {
if (entry.getValue().getRegionInfo().getTable().equals(this.tableName)) {
key = entry.getKey();
break;
}
}
rs.onlineRegions.put(key, spiedRegion);
Connection conn = testUtil.getConnection();
try (Table table = conn.getTable(tableName)) {
table.put(new Put(Bytes.toBytes("row0"))
.addColumn(family, qualifier, Bytes.toBytes("val0")));
}
long oldestSeqIdOfStore = region.getOldestSeqIdOfStore(family);
LOG.info("CHANGE OLDEST " + oldestSeqIdOfStore);
assertTrue(oldestSeqIdOfStore > HConstants.NO_SEQNUM);
rs.cacheFlusher.requestFlush(spiedRegion, false, FlushLifeCycleTracker.DUMMY);
synchronized (flushed) {
while (!flushed.booleanValue()) {
flushed.wait();
}
}
try (Table table = conn.getTable(tableName)) {
table.put(new Put(Bytes.toBytes("row1"))
.addColumn(family, qualifier, Bytes.toBytes("val1")));
}
long now = EnvironmentEdgeManager.currentTime();
rs.tryRegionServerReport(now - 500, now);
synchronized (reported) {
reported.setValue(true);
reported.notifyAll();
}
while (testUtil.getRSForFirstRegionInTable(tableName) == rs) {
Thread.sleep(100);
}
try (Table table = conn.getTable(tableName)) {
Result result = table.get(new Get(Bytes.toBytes("row0")));
assertArrayEquals(Bytes.toBytes("val0"), result.getValue(family, qualifier));
}
}
示例9: handleScanError
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
private void handleScanError(DoNotRetryIOException e,
MutableBoolean retryAfterOutOfOrderException, int retriesLeft) throws DoNotRetryIOException {
// An exception was thrown which makes any partial results that we were collecting
// invalid. The scanner will need to be reset to the beginning of a row.
scanResultCache.clear();
// Unfortunately, DNRIOE is used in two different semantics.
// (1) The first is to close the client scanner and bubble up the exception all the way
// to the application. This is preferred when the exception is really un-recoverable
// (like CorruptHFileException, etc). Plain DoNotRetryIOException also falls into this
// bucket usually.
// (2) Second semantics is to close the current region scanner only, but continue the
// client scanner by overriding the exception. This is usually UnknownScannerException,
// OutOfOrderScannerNextException, etc where the region scanner has to be closed, but the
// application-level ClientScanner has to continue without bubbling up the exception to
// the client. See RSRpcServices to see how it throws DNRIOE's.
// See also: HBASE-16604, HBASE-17187
// If exception is any but the list below throw it back to the client; else setup
// the scanner and retry.
Throwable cause = e.getCause();
if ((cause != null && cause instanceof NotServingRegionException) ||
(cause != null && cause instanceof RegionServerStoppedException) ||
e instanceof OutOfOrderScannerNextException || e instanceof UnknownScannerException ||
e instanceof ScannerResetException) {
// Pass. It is easier writing the if loop test as list of what is allowed rather than
// as a list of what is not allowed... so if in here, it means we do not throw.
if (retriesLeft <= 0) {
throw e; // no more retries
}
} else {
throw e;
}
// Else, its signal from depths of ScannerCallable that we need to reset the scanner.
if (this.lastResult != null) {
// The region has moved. We need to open a brand new scanner at the new location.
// Reset the startRow to the row we've seen last so that the new scanner starts at
// the correct row. Otherwise we may see previously returned rows again.
// If the lastRow is not partial, then we should start from the next row. As now we can
// exclude the start row, the logic here is the same for both normal scan and reversed scan.
// If lastResult is partial then include it, otherwise exclude it.
scan.withStartRow(lastResult.getRow(), lastResult.mayHaveMoreCellsInRow());
}
if (e instanceof OutOfOrderScannerNextException) {
if (retryAfterOutOfOrderException.isTrue()) {
retryAfterOutOfOrderException.setValue(false);
} else {
// TODO: Why wrap this in a DNRIOE when it already is a DNRIOE?
throw new DoNotRetryIOException(
"Failed after retry of OutOfOrderScannerNextException: was there a rpc timeout?", e);
}
}
// Clear region.
this.currentRegion = null;
// Set this to zero so we don't try and do an rpc and close on remote server when
// the exception we got was UnknownScanner or the Server is going down.
callable = null;
}
示例10: expiredTestBlockingExpiredFirstValidLast
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
@Test
public void expiredTestBlockingExpiredFirstValidLast() throws Exception
{
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
MutableBoolean queueContext = new MutableBoolean(false);
sdqqm.enqueue(query, null, queueContext);
Query query1 = new MockQuery("2");
MutableBoolean queueContext1 = new MutableBoolean(false);
sdqqm.enqueue(query1, null, queueContext1);
Assert.assertEquals(2, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
sdqqm.endWindow();
sdqqm.beginWindow(1);
Assert.assertEquals(2, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
queueContext.setValue(true);
qb = sdqqm.dequeueBlock();
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
testBlocking(sdqqm);
sdqqm.endWindow();
sdqqm.beginWindow(2);
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
qb = sdqqm.dequeueBlock();
testBlocking(sdqqm);
sdqqm.endWindow();
sdqqm.teardown();
}
示例11: expiredTestBlockingValidFirstExpiredLast
import org.apache.commons.lang3.mutable.MutableBoolean; //导入方法依赖的package包/类
@Test
public void expiredTestBlockingValidFirstExpiredLast() throws Exception
{
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
MutableBoolean queueContext = new MutableBoolean(false);
sdqqm.enqueue(query, null, queueContext);
Query query1 = new MockQuery("2");
MutableBoolean queueContext1 = new MutableBoolean(false);
sdqqm.enqueue(query1, null, queueContext1);
Assert.assertEquals(2, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
sdqqm.endWindow();
sdqqm.beginWindow(1);
Assert.assertEquals(2, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
queueContext1.setValue(true);
qb = sdqqm.dequeueBlock();
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
testBlocking(sdqqm);
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
sdqqm.endWindow();
sdqqm.beginWindow(2);
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
qb = sdqqm.dequeueBlock();
testBlocking(sdqqm);
sdqqm.endWindow();
sdqqm.teardown();
}