Example usage for java.util.concurrent.atomic AtomicBoolean set

List of usage examples for java.util.concurrent.atomic AtomicBoolean set

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicBoolean set.

Prototype

public final void set(boolean newValue) 

Source Link

Document

Sets the value to newValue , with memory effects as specified by VarHandle#setVolatile .

Usage

From source file:net.sourceforge.ganttproject.io.CsvImportTest.java

public void testIncompleteHeader() throws IOException {
    String header = "A, B";
    String data = "a1, b1";
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    GanttCSVOpen.RecordGroup recordGroup = new GanttCSVOpen.RecordGroup("ABC",
            ImmutableSet.<String>of("A", "B", "C"), // all fields
            ImmutableSet.<String>of("A", "B")) { // mandatory fields
        @Override/*from  ww  w . j  a  v a2s .com*/
        protected boolean doProcess(CSVRecord record) {
            wasCalled.set(true);
            assertEquals("a1", record.get("A"));
            assertEquals("b1", record.get("B"));
            return true;
        }
    };
    GanttCSVOpen importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(header, data)), recordGroup);
    importer.load();
    assertTrue(wasCalled.get());
}

From source file:biz.ganttproject.impex.csv.CsvImportTest.java

public void testBasic() throws Exception {
    String header = "A, B";
    String data = "a1, b1";
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    RecordGroup recordGroup = new RecordGroup("AB", ImmutableSet.<String>of("A", "B")) {
        @Override//from   w  w w .j ava2s .c  o  m
        protected boolean doProcess(CSVRecord record) {
            if (!super.doProcess(record)) {
                return false;
            }
            wasCalled.set(true);
            assertEquals("a1", record.get("A"));
            assertEquals("b1", record.get("B"));
            return true;
        }
    };
    GanttCSVOpen importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(header, data)), recordGroup);
    importer.load();
    assertTrue(wasCalled.get());
}

From source file:biz.ganttproject.impex.csv.CsvImportTest.java

public void testSkipEmptyLine() throws Exception {
    String header = "A, B";
    String data = "a1, b1";
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    RecordGroup recordGroup = new RecordGroup("AB", ImmutableSet.<String>of("A", "B")) {
        @Override//from   ww  w  .  ja  va  2 s . co  m
        protected boolean doProcess(CSVRecord record) {
            if (!super.doProcess(record)) {
                return false;
            }
            wasCalled.set(true);
            assertEquals("a1", record.get("A"));
            assertEquals("b1", record.get("B"));
            return true;
        }
    };
    GanttCSVOpen importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(header, "", data)),
            recordGroup);
    importer.load();
    assertTrue(wasCalled.get());
}

From source file:biz.ganttproject.impex.csv.CsvImportTest.java

public void testSkipUntilFirstHeader() throws IOException {
    String notHeader = "FOO, BAR, A";
    String header = "A, B";
    String data = "a1, b1";
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    RecordGroup recordGroup = new RecordGroup("ABC", ImmutableSet.<String>of("A", "B")) {
        @Override/*from w w w.j  a  va  2  s.c  om*/
        protected boolean doProcess(CSVRecord record) {
            if (!super.doProcess(record)) {
                return false;
            }
            wasCalled.set(true);
            assertEquals("a1", record.get("A"));
            assertEquals("b1", record.get("B"));
            return true;
        }
    };
    GanttCSVOpen importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(notHeader, header, data)),
            recordGroup);
    importer.load();
    assertTrue(wasCalled.get());
    assertEquals(1, importer.getSkippedLineCount());
}

From source file:com.jayway.restassured.examples.springmvc.controller.AutoSpringSecurityConfigurerITest.java

@Test
public void doesnt_add_spring_security_configurer_automatically_when_a_spring_security_configurer_has_been_manually_applied() {
    final AtomicBoolean filterUsed = new AtomicBoolean(false);

    given().webAppContextSetup(context, springSecurity(), springSecurity(new Filter() {
        public void init(FilterConfig filterConfig) throws ServletException {
        }// w  w  w .ja  v  a2  s  .  c  o m

        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                throws IOException, ServletException {
            filterUsed.set(true);
            chain.doFilter(request, response);
        }

        public void destroy() {
        }
    })).postProcessors(httpBasic("username", "password")).param("name", "Johan").when().get("/secured/greeting")
            .then().statusCode(200).body("content", equalTo("Hello, Johan!"))
            .expect(authenticated().withUsername("username"));

    assertThat(filterUsed.get(), is(true));
}

From source file:org.apache.nifi.processors.windows.event.log.ConsumeWindowsEventLogTest.java

@Test(timeout = 10 * 1000)
public void testProcessesBlockedEvents() throws UnsupportedEncodingException {
    testRunner.setProperty(ConsumeWindowsEventLog.MAX_EVENT_QUEUE_SIZE, "1");
    testRunner.run(1, false, true);//www  . j  a v  a2 s . c o  m
    EventSubscribeXmlRenderingCallback renderingCallback = getRenderingCallback();

    List<String> eventXmls = Arrays.asList("one", "two", "three", "four", "five", "six");
    List<WinNT.HANDLE> eventHandles = mockEventHandles(wEvtApi, kernel32, eventXmls);
    AtomicBoolean done = new AtomicBoolean(false);
    new Thread(() -> {
        for (WinNT.HANDLE eventHandle : eventHandles) {
            renderingCallback.onEvent(WEvtApi.EvtSubscribeNotifyAction.DELIVER, null, eventHandle);
        }
        done.set(true);
    }).start();

    // Wait until the thread has really started
    while (testRunner.getFlowFilesForRelationship(ConsumeWindowsEventLog.REL_SUCCESS).size() == 0) {
        testRunner.run(1, false, false);
    }

    // Process rest of events
    while (!done.get()) {
        testRunner.run(1, false, false);
    }

    testRunner.run(1, true, false);

    List<MockFlowFile> flowFilesForRelationship = testRunner
            .getFlowFilesForRelationship(ConsumeWindowsEventLog.REL_SUCCESS);
    assertEquals(eventXmls.size(), flowFilesForRelationship.size());
    for (int i = 0; i < eventXmls.size(); i++) {
        flowFilesForRelationship.get(i).assertContentEquals(eventXmls.get(i));
    }
}

From source file:org.alfresco.repo.activities.post.cleanup.PostCleaner.java

public void execute() throws JobExecutionException {
    final AtomicBoolean keepGoing = new AtomicBoolean(true);
    String lockToken = null;/*from w w w.j ava  2  s  . c  om*/
    try {
        // Lock
        lockToken = jobLockService.getLock(LOCK_QNAME, LOCK_TTL);
        // Refresh to get callbacks
        JobLockRefreshCallback callback = new JobLockRefreshCallback() {
            @Override
            public void lockReleased() {
                keepGoing.set(false);
            }

            @Override
            public boolean isActive() {
                return keepGoing.get();
            }
        };
        jobLockService.refreshLock(lockToken, LOCK_QNAME, LOCK_TTL, callback);

        executeWithLock();
    } catch (LockAcquisitionException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Skipping post cleaning.  " + e.getMessage());
        }
    } finally {
        keepGoing.set(false); // Notify the refresh callback that we are done
        if (lockToken != null) {
            jobLockService.releaseLock(lockToken, LOCK_QNAME);
        }
    }
}

From source file:com.facebook.buck.artifact_cache.ArtifactUploaderTest.java

@Test
public void testPerformUploadToArtifactCache() throws IOException {

    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();

    byte[] contents = "contents".getBytes();

    Path file = Paths.get("file");
    filesystem.writeBytesToPath(contents, file);

    Path dirFile = Paths.get("dir", "file");
    filesystem.createParentDirs(dirFile);
    filesystem.writeBytesToPath(contents, dirFile);

    Path metadataFile = Paths.get("buck-out", "bin", "foo", ".bar", "metadata", "artifact", "metadata");
    filesystem.createParentDirs(metadataFile);
    filesystem.writeBytesToPath(contents, metadataFile);

    Path dir = Paths.get("buck-out", "bin", "foo", ".bar/");
    filesystem.mkdirs(dir);//from   www  .  ja  v  a 2  s.co m

    AtomicBoolean stored = new AtomicBoolean(false);
    ArtifactCache cache = new NoopArtifactCache() {
        @Override
        public CacheReadMode getCacheReadMode() {
            return CacheReadMode.READWRITE;
        }

        @Override
        public ListenableFuture<Void> store(ArtifactInfo info, BorrowablePath output) {
            stored.set(true);

            // Verify the build metadata.
            assertThat(info.getMetadata().get("build-metadata"), Matchers.equalTo("build-metadata"));

            // Unarchive file.
            final ImmutableMap<String, byte[]> archiveContents;
            try {
                archiveContents = TarInspector.readTarZst(output.getPath());
            } catch (IOException | CompressorException e) {
                fail(e.getMessage());
                return Futures.immediateFuture(null);
            }

            // Verify archive contents.
            assertEquals(ImmutableSet.of("buck-out/bin/foo/.bar/", "dir/file", "file",
                    "buck-out/bin/foo/.bar/metadata/artifact/metadata"), archiveContents.keySet());
            assertArrayEquals(contents, archiveContents.get("file"));
            assertArrayEquals(contents, archiveContents.get("dir/file"));
            assertArrayEquals(contents,
                    archiveContents.get("buck-out/bin/foo/.bar/metadata/artifact/metadata"));
            return Futures.immediateFuture(null);
        }
    };

    ArtifactUploader.performUploadToArtifactCache(ImmutableSet.of(new RuleKey("aa")), cache,
            BuckEventBusForTests.newInstance(),
            ImmutableMap.of("metadata", "metadata", "build-metadata", "build-metadata"),
            ImmutableSortedSet.of(dir, file, dirFile, metadataFile), BUILD_TARGET, filesystem, 1000);

    assertTrue(stored.get());
}

From source file:com.qq.tars.service.server.ServerService.java

public ServerConf getServerConf4Tree(String treeNodeId) {
    ServerConf serverConf = new ServerConf();
    AtomicBoolean enableSet = new AtomicBoolean(false);
    Arrays.stream(treeNodeId.split("\\.")).forEach(s -> {
        int i = Integer.parseInt(s.substring(0, 1));
        String v = s.substring(1);
        switch (i) {
        case 1:// w w w  .  j av  a2  s .c  o  m
            serverConf.setApplication(v);
            break;
        case 2:
            serverConf.setSetName(v);
            enableSet.set(true);
            break;
        case 3:
            serverConf.setSetArea(v);
            enableSet.set(true);
            break;
        case 4:
            serverConf.setSetGroup(v);
            enableSet.set(true);
            break;
        case 5:
            serverConf.setServerName(v);
            break;
        default:
            break;
        }
    });
    serverConf.setEnableSet(enableSet.get() ? "Y" : "N");
    return serverConf;
}

From source file:com.kixeye.chassis.support.test.hystrix.ChassisHystrixTest.java

@Test
@SuppressWarnings("unused")
public void testCommandTimeOut() throws InterruptedException {
    final AtomicBoolean done = new AtomicBoolean(false);

    // kick off async command
    Observable<String> observable = new TestTimeOutCommand().observe();

    // Add handler
    observable.subscribe(new Observer<String>() {
        @Override/*from w  w  w.  ja  va2 s.c o  m*/
        public void onCompleted() {
            Assert.assertNull("Should not complete");
            done.set(true);
        }

        @Override
        public void onError(Throwable e) {
            done.set(true);
        }

        @Override
        public void onNext(String args) {
            Assert.assertNull("Should not get a result");
            done.set(true);
        }
    });

    // spin until done
    while (!done.get()) {
        Thread.sleep(100);
    }
}