List of usage examples for org.apache.commons.lang3.mutable MutableObject getValue
@Override
public T getValue()
From source file:com.jayway.restassured.module.mockmvc.ResultHandlerTest.java
@Test public void merges_result_handlers_using_the_dsl() { MutableObject<Boolean> mutableObject1 = new MutableObject<Boolean>(false); MutableObject<Boolean> mutableObject2 = new MutableObject<Boolean>(false); given().resultHandlers(customResultHandler(mutableObject1)) .resultHandlers(customResultHandler(mutableObject2)).header(new Header("headerName", "John Doe")) .when().get("/header").then().statusCode(200).body("headerName", equalTo("John Doe")); assertThat(mutableObject1.getValue(), is(true)); assertThat(mutableObject2.getValue(), is(true)); }
From source file:com.jayway.restassured.module.mockmvc.ResultHandlerTest.java
@Test public void merges_statically_defined_result_handlers_with_dsl_defined_using_response_spec() { MutableObject<Boolean> mutableObject1 = new MutableObject<Boolean>(false); MutableObject<Boolean> mutableObject2 = new MutableObject<Boolean>(false); RestAssuredMockMvc.resultHandlers(customResultHandler(mutableObject1)); given().header(new Header("headerName", "John Doe")).when().get("/header").then() .apply(customResultHandler(mutableObject2)).statusCode(200).body("headerName", equalTo("John Doe")); assertThat(mutableObject1.getValue(), is(true)); assertThat(mutableObject2.getValue(), is(true)); }
From source file:com.jayway.restassured.module.mockmvc.ResultHandlerTest.java
@Test public void merges_statically_defined_result_handlers_with_dsl_defined() { MutableObject<Boolean> mutableObject1 = new MutableObject<Boolean>(false); MutableObject<Boolean> mutableObject2 = new MutableObject<Boolean>(false); RestAssuredMockMvc.resultHandlers(customResultHandler(mutableObject1)); given().resultHandlers(customResultHandler(mutableObject2)).header(new Header("headerName", "John Doe")) .when().get("/header").then().statusCode(200).body("headerName", equalTo("John Doe")); assertThat(mutableObject1.getValue(), is(true)); assertThat(mutableObject2.getValue(), is(true)); }
From source file:com.wolvereness.renumerated.Renumerated.java
private void process() throws Throwable { validateInput();// www. jav a 2 s . co m final MultiProcessor executor = MultiProcessor.newMultiProcessor(cores - 1, new ThreadFactoryBuilder().setDaemon(true) .setNameFormat(Renumerated.class.getName() + "-processor-%d") .setUncaughtExceptionHandler(this).build()); final Future<?> fileCopy = executor.submit(new Callable<Object>() { @Override public Object call() throws Exception { if (original != null) { if (original.exists()) { original.delete(); } Files.copy(input, original); } return null; } }); final List<Pair<ZipEntry, Future<byte[]>>> fileEntries = newArrayList(); final List<Pair<MutableObject<ZipEntry>, Future<byte[]>>> classEntries = newArrayList(); { final ZipFile input = new ZipFile(this.input); final Enumeration<? extends ZipEntry> inputEntries = input.entries(); while (inputEntries.hasMoreElements()) { final ZipEntry entry = inputEntries.nextElement(); final Future<byte[]> future = executor.submit(new Callable<byte[]>() { @Override public byte[] call() throws Exception { return ByteStreams.toByteArray(input.getInputStream(entry)); } }); if (entry.getName().endsWith(".class")) { classEntries.add(new MutablePair<MutableObject<ZipEntry>, Future<byte[]>>( new MutableObject<ZipEntry>(entry), future)); } else { fileEntries.add(new ImmutablePair<ZipEntry, Future<byte[]>>(entry, future)); } } for (final Pair<MutableObject<ZipEntry>, Future<byte[]>> pair : classEntries) { final byte[] data = pair.getRight().get(); pair.setValue(executor.submit(new Callable<byte[]>() { String className; List<String> fields; @Override public byte[] call() throws Exception { try { return method(); } catch (final Exception ex) { throw new Exception(pair.getLeft().getValue().getName(), ex); } } private byte[] method() throws Exception { final ClassReader clazz = new ClassReader(data); clazz.accept(new ClassVisitor(ASM4) { @Override public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { if (superName.equals("java/lang/Enum")) { className = name; } } @Override public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) { if (className != null && (access & 0x4000) != 0) { List<String> fieldNames = fields; if (fieldNames == null) { fieldNames = fields = newArrayList(); } fieldNames.add(name); } return null; } }, ClassReader.SKIP_CODE); if (className == null) return data; final String classDescriptor = Type.getObjectType(className).getDescriptor(); final ClassWriter writer = new ClassWriter(0); clazz.accept(new ClassVisitor(ASM4, writer) { @Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { final MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); if (!name.equals("<clinit>")) { return methodVisitor; } return new MethodVisitor(ASM4, methodVisitor) { final Iterator<String> it = fields.iterator(); boolean active; String lastName; @Override public void visitTypeInsn(final int opcode, final String type) { if (!active && it.hasNext()) { // Initiate state machine if (opcode != NEW) throw new AssertionError("Unprepared for " + opcode + " on " + type + " in " + className); active = true; } super.visitTypeInsn(opcode, type); } @Override public void visitLdcInsn(final Object cst) { if (active && lastName == null) { if (!(cst instanceof String)) throw new AssertionError( "Unprepared for " + cst + " in " + className); // Switch the first constant in the Enum constructor super.visitLdcInsn(lastName = it.next()); } else { super.visitLdcInsn(cst); } } @Override public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { if (opcode == PUTSTATIC && active && lastName != null && owner.equals(className) && desc.equals(classDescriptor) && name.equals(lastName)) { // Finish the current state machine active = false; lastName = null; } super.visitFieldInsn(opcode, owner, name, desc); } }; } }, ClassReader.EXPAND_FRAMES); final MutableObject<ZipEntry> key = pair.getLeft(); key.setValue(new ZipEntry(key.getValue().getName())); return writer.toByteArray(); } })); } for (final Pair<ZipEntry, Future<byte[]>> pair : fileEntries) { pair.getRight().get(); } input.close(); } fileCopy.get(); FileOutputStream fileOut = null; JarOutputStream jar = null; try { jar = new JarOutputStream(fileOut = new FileOutputStream(output)); for (final Pair<ZipEntry, Future<byte[]>> fileEntry : fileEntries) { jar.putNextEntry(fileEntry.getLeft()); jar.write(fileEntry.getRight().get()); } for (final Pair<MutableObject<ZipEntry>, Future<byte[]>> classEntry : classEntries) { final byte[] data = classEntry.getRight().get(); final ZipEntry entry = classEntry.getLeft().getValue(); entry.setSize(data.length); jar.putNextEntry(entry); jar.write(data); } } finally { if (jar != null) { try { jar.close(); } catch (final IOException ex) { } } if (fileOut != null) { try { fileOut.close(); } catch (final IOException ex) { } } } final Pair<Thread, Throwable> uncaught = this.uncaught; if (uncaught != null) throw new MojoExecutionException(String.format("Uncaught exception in %s", uncaught.getLeft()), uncaught.getRight()); }
From source file:com.romeikat.datamessie.core.processing.task.documentProcessing.DocumentsProcessingTask.java
private void performProcessing(final TaskExecution taskExecution) throws TaskCancelledException { // Initialize taskExecution.reportWork("Starting documents processing"); // Determine minimum downloaded date final LocalDate minDownloadedDate = getMinDownloadedDate(sessionProvider.getStatelessSession()); // Process all download dates one after another, starting with the minimum downloaded date final MutableObject<LocalDate> downloadedDate = new MutableObject<LocalDate>(minDownloadedDate); while (true) { // Load/* w w w.j ava 2 s.co m*/ final List<Document> documentsToProcess = documentsLoader.loadDocumentsToProcess( sessionProvider.getStatelessSession(), taskExecution, downloadedDate.getValue(), failedDocumentIds); // Process if (CollectionUtils.isNotEmpty(documentsToProcess)) { final String singularPlural = stringUtil.getSingularOrPluralTerm("document", documentsToProcess.size()); final TaskExecutionWork work = taskExecution.reportWorkStart( String.format("Processing %s %s", documentsToProcess.size(), singularPlural)); final DocumentsProcessor documentsProcessor = new DocumentsProcessor(ctx); documentsProcessor.processDocuments(documentsToProcess); failedDocumentIds.addAll(documentsProcessor.getFailedDocumentIds()); rebuildStatistics(documentsProcessor.getStatisticsToBeRebuilt()); reindexDocuments(documentsToProcess); taskExecution.reportWorkEnd(work); taskExecution.checkpoint(); } // Prepare for next iteration prepareForNextIteration(taskExecution, downloadedDate, documentsToProcess); } }
From source file:com.jayway.restassured.itest.java.AcceptHeaderITest.java
@Test public void accept_headers_are_overwritten_from_request_spec_by_default() { RequestSpecification spec = new RequestSpecBuilder().setAccept(JSON).build(); final MutableObject<List<String>> headers = new MutableObject<List<String>>(); given().accept("text/jux").spec(spec).body("{ \"message\" : \"hello world\"}").filter(new Filter() { public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { headers.setValue(requestSpec.getHeaders().getValues("Accept")); return ctx.next(requestSpec, responseSpec); }//from www . ja v a2 s.co m }).when().post("/jsonBodyAcceptHeader").then().body(equalTo("hello world")); assertThat(headers.getValue(), contains("application/json, application/javascript, text/javascript")); }
From source file:gov.va.isaac.workflow.engine.RemoteSynchronizer.java
/** * Request a remote synchronization. This call blocks until the operation is complete, * or the thread is interrupted.//from w ww. j a v a 2 s . c om * * @throws InterruptedException */ public SynchronizeResult blockingSynchronize() throws InterruptedException { log.info("Queuing a blocking sync request"); final MutableObject<SynchronizeResult> result = new MutableObject<SynchronizeResult>(); final CountDownLatch cdl = new CountDownLatch(1); Consumer<SynchronizeResult> callback = new Consumer<SynchronizeResult>() { @Override public void accept(SynchronizeResult t) { result.setValue(t); cdl.countDown(); } }; synchronize(callback); cdl.await(); return result.getValue(); }
From source file:fr.duminy.jbackup.core.JBackupImplTest.java
private void waitTaskStarted(MutableBoolean taskStarted, MutableObject<Cancellable> actualCancellable) throws InterruptedException { long start = currentTimeMillis(); do {//from ww w . jav a 2 s . c om Thread.sleep(100); } while (((actualCancellable.getValue() == null) || taskStarted.isFalse()) && ((currentTimeMillis() - start) < 1000)); }
From source file:io.restassured.itest.java.AcceptHeaderITest.java
@Test public void accept_headers_are_overwritten_from_request_spec_by_default() { RequestSpecification spec = new RequestSpecBuilder().setAccept(ContentType.JSON).build(); final MutableObject<List<String>> headers = new MutableObject<List<String>>(); RestAssured.given().accept("text/jux").spec(spec).body("{ \"message\" : \"hello world\"}") .filter(new Filter() { public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { headers.setValue(requestSpec.getHeaders().getValues("Accept")); return ctx.next(requestSpec, responseSpec); }//from w w w. ja v a2s . c o m }).when().post("/jsonBodyAcceptHeader").then().body(equalTo("hello world")); assertThat(headers.getValue(), contains("application/json, application/javascript, text/javascript")); }
From source file:com.flipkart.flux.client.runtime.LocalContextTest.java
@Test public void shouldAllowSameMethodRegistrationFromDifferentThreads() throws Exception { final MutableObject<StateMachineDefinition> definitionOne = new MutableObject<>(null); final MutableObject<StateMachineDefinition> definitionTwo = new MutableObject<>(null); final Thread thread1 = new Thread(() -> { localContext.registerNew("fooBar", 1, "someDescription", "someContext"); definitionOne.setValue(tlStateMachineDef.get()); });/*w w w . ja v a2 s . c o m*/ final Thread thread2 = new Thread(() -> { localContext.registerNew("fooBar", 1, "someDescription", "someContext"); definitionTwo.setValue(tlStateMachineDef.get()); }); thread1.start(); thread2.start(); thread1.join(); thread2.join(); assertThat(definitionOne.getValue()).isNotNull().isEqualTo(definitionTwo.getValue()) .isEqualTo(new StateMachineDefinition("someDescription", "fooBar", 1l, new HashSet<>(), new HashSet<>(), "someContext")); }