Example usage for java.util Queue toString

List of usage examples for java.util Queue toString

Introduction

In this page you can find the example usage for java.util Queue toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:net.swas.explorer.servlet.ms.GetAuditLog.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 *//* w ww .  j  a  v a  2 s.  c o m*/
@SuppressWarnings("unchecked")
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();

    try {

        JSONObject respJson = new JSONObject();

        if (AuditLogCache.isAELInitialized()) {

            if (AuditLogCache.getAEL().size() > 0) {

                Queue<JSONObject> list = AuditLogCache.getAEL();

                out.print(list.toString());
                log.info("GetAudit Already have : " + list.toString());
                //AuditLogCache.flushAEL();

            } else {

                respJson.put("status", "1");
                log.info("Sending Json : " + respJson.toString());
                out.print(respJson.toString());

            }

        } else {

            respJson.put("status", "1");
            log.info("Sending Json : " + respJson.toString());
            out.print(respJson.toString());
        }

    } finally {
        out.close();
    }

}

From source file:com.android.pwdhashandroid.pwdhash.PasswordHasher.java

private char[] rotate(char[] arr, int amount) {
    //      Log.d(tag, amount + "x:\t");

    Queue<Character> q = CreateQueue(arr);

    while (amount-- != 0) {
        q.add(q.remove());/*from w w w.  j av  a  2 s. c  o  m*/
        Log.d(tag, q.toString());
    }

    Character[] chars = (Character[]) q.toArray(new Character[0]);
    return CharacterToCharArray(chars);

    //      return new char[10]; 

    //      CSQueue q = new CSQueue(arr);
    //      while (amount-- != 0) {
    //         q.put(q.get());
    //         Log.d(tag, new String(q.toArray()));
    //      }
    //
    //      return q.toArray();
}

From source file:org.apache.usergrid.mq.Message.java

public void setReplyTo(Queue destination) {
    properties.put(MESSAGE_REPLY_TO, destination.toString());
}

From source file:org.apache.usergrid.mq.Message.java

public void setDestination(Queue destination) {
    properties.put(MESSAGE_CORRELATION_ID, destination.toString());
}

From source file:org.wso2.appserver.integration.tests.qualityofservice.throtllingservice.ThrottlingTestCase.java

@Test(groups = "wso2.as", description = "IP controlled for other concurrent test", dependsOnMethods = "accessLevelControlledConcurrentLocalHost", enabled = false)
public void accessLevelControlledConcurrentOther() throws Exception {
    // always maxConcurrent value should be lesser than no of concurrent threads (threadGroup *  threadLoop)
    // while maxRequestCount should be a larger value than no of concurrent threads
    int maxConcurrent = 10;
    int threadGroup = 20;
    int threadLoop = 1;
    int maxRequestCount = 100;

    internalData.setRange("other"); // ip host address
    internalData.setRangeType("IP"); //Type of Range. IP/DOMAIN
    internalData.setMaxRequestCount(maxRequestCount); // maximum requests served under unit time parameter
    internalData.setUnitTime(50000); // time period maximum requests served in
    internalData.setProhibitTimePeriod(1000); // requests not allowed time period.
    internalData.setAccessLevel(ACCESS_CONTROLLED); // access level

    assertTrue(enableThrottling(internalDataArr, maxConcurrent));

    ConcurrencyTest concurrencyTest = new ConcurrencyTest(threadGroup, threadLoop);
    concurrencyTest.run(getServiceUrl("echo"), createPayLoad(), "echoInt"); // sending concurrent requests
    Queue<OMElement> messageQueue = concurrencyTest.getMessages();
    log.info(messageQueue.toString());//TODO WSAS-1230
}

From source file:org.syncany.tests.integration.scenarios.Issue429ScenarioTest.java

@Ignore
public void testSameFileDifferentNameFuzzy() throws Exception {
    for (int seed = 0; seed < 1000; seed++) {
        LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil
                .createTestLocalConnection();

        TestClient clientA = new TestClient("A", testConnection);
        TestClient clientB = new TestClient("B", testConnection);

        Random randomA = new Random(2 * seed);
        Random randomB = new Random(2 * seed + 1);

        Queue<String> queue = new ConcurrentLinkedQueue<>();

        activeThread A = new activeThread(randomA, clientA, queue);
        activeThread B = new activeThread(randomB, clientB, queue);
        Thread AThread = new Thread(A, "A");
        Thread BThread = new Thread(B, "B");
        try {/*  w  w w. j  ava2 s . c o m*/
            AThread.start();
            BThread.start();
            //            int actionsA = -1;
            //            int actionsB = -1;

            for (int i = 0; i < 50; i++) {
                TestClient clientC = new TestClient("C", testConnection);
                clientC.down();
                if (!AThread.isAlive() || !BThread.isAlive()) {
                    throw new RuntimeException("One of the threads died");
                }

                FileUtils.deleteDirectory(clientC.getLocalFile(""));
                Thread.sleep(2000);
            }

            AThread.interrupt();
            BThread.interrupt();
        } catch (Exception e) {
            logger.log(Level.INFO, "Queue:" + queue.toString());
            logger.log(Level.INFO, "Something went wrong at seed: " + seed);
            throw e;
        }
        clientA.deleteTestData();
        clientB.deleteTestData();
    }
}

From source file:org.eobjects.analyzer.result.AnalyzerResultFutureTest.java

public void testMultiThreadedListenerScenario() throws Exception {
    final int threadCount = 10;

    final Thread[] threads = new Thread[threadCount];
    @SuppressWarnings({ "unchecked" })
    final Listener<NumberResult>[] listeners = new Listener[threadCount];
    final Queue<Object> resultQueue = new ArrayBlockingQueue<>(threadCount);

    for (int i = 0; i < listeners.length; i++) {
        listeners[i] = new Listener<NumberResult>() {
            @Override/*from w w w .  j a  v a  2s.  c  om*/
            public void onSuccess(NumberResult result) {
                resultQueue.add(result);
            }

            @Override
            public void onError(RuntimeException error) {
                resultQueue.add(error);
            }
        };
    }

    final Ref<NumberResult> resultRef = new LazyRef<NumberResult>() {
        @Override
        protected NumberResult fetch() throws Throwable {
            long randomSleepTime = (long) (1000 * Math.random());
            Thread.sleep(randomSleepTime);
            return new NumberResult(43);
        }
    };

    final AnalyzerResultFuture<NumberResult> future = new AnalyzerResultFuture<>("foo", resultRef);

    for (int i = 0; i < threads.length; i++) {
        final Listener<NumberResult> listener = listeners[i];
        threads[i] = new Thread() {
            @Override
            public void run() {
                future.addListener(listener);
            }
        };
    }

    final int halfOfTheThreads = threads.length / 2;
    for (int i = 0; i < halfOfTheThreads; i++) {
        threads[i].start();
    }
    for (int i = 0; i < halfOfTheThreads; i++) {
        threads[i].join();
    }

    future.get();

    assertEquals("[43, 43, 43, 43, 43]", resultQueue.toString());
    assertEquals(halfOfTheThreads, resultQueue.size());

    for (int i = halfOfTheThreads; i < threads.length; i++) {
        threads[i].start();
    }
    for (int i = halfOfTheThreads; i < threads.length; i++) {
        threads[i].join();
    }

    assertEquals("[43, 43, 43, 43, 43, 43, 43, 43, 43, 43]", resultQueue.toString());
    assertEquals(threads.length, resultQueue.size());
}

From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java

@Test
@DisplayName("Change publisher dynamically")
void changePublisherTest() throws Exception {

    Queue<Boolean> threadAssertions = new ConcurrentLinkedQueue<Boolean>();

    setupBrowser("chrome");

    log.info("Change publisher dynamically");

    WebElement oneToManyInput = user.getDriver().findElement(By.id("one2many-input"));
    oneToManyInput.clear();//  w  ww . jav a 2 s  . co  m
    oneToManyInput.sendKeys("1");

    user.getDriver().findElement(By.id("auto-join-checkbox")).click();

    final CountDownLatch latch1 = new CountDownLatch(2);

    // First publication (audio + video [CAMERA])
    user.getEventManager().on("streamPlaying", (event) -> {
        JsonObject stream = event.get("target").getAsJsonObject().get("stream").getAsJsonObject();
        threadAssertions.add("CAMERA".equals(stream.get("typeOfVideo").getAsString()));
        threadAssertions.add(stream.get("hasAudio").getAsBoolean());

        latch1.countDown();
    });
    user.getDriver().findElement(By.id("one2many-btn")).click();

    user.getEventManager().waitUntilEventReaches("connectionCreated", 4);
    user.getEventManager().waitUntilEventReaches("accessAllowed", 1);
    user.getEventManager().waitUntilEventReaches("streamCreated", 2);
    user.getEventManager().waitUntilEventReaches("streamPlaying", 2);

    if (!latch1.await(5000, TimeUnit.MILLISECONDS)) {
        gracefullyLeaveParticipants(2);
        fail("Waiting for 2 streamPlaying events to happen in total");
        return;
    }

    user.getEventManager().off("streamPlaying");
    log.info("Thread assertions: {}", threadAssertions.toString());
    for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) {
        Assert.assertTrue("Some Event property was wrong", iter.next());
        iter.remove();
    }

    int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
    Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos);
    Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager()
            .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true));

    final CountDownLatch latch2 = new CountDownLatch(2);

    // Second publication (only video (SCREEN))
    user.getEventManager().on("streamPlaying", (event) -> {
        JsonObject stream = event.get("target").getAsJsonObject().get("stream").getAsJsonObject();
        threadAssertions.add("SCREEN".equals(stream.get("typeOfVideo").getAsString()));
        threadAssertions.add(!stream.get("hasAudio").getAsBoolean());
        latch2.countDown();
    });
    user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .change-publisher-btn")).click();

    user.getEventManager().waitUntilEventReaches("streamDestroyed", 2);
    user.getEventManager().waitUntilEventReaches("accessAllowed", 2);
    user.getEventManager().waitUntilEventReaches("streamCreated", 4);
    user.getEventManager().waitUntilEventReaches("streamPlaying", 4);

    if (!latch2.await(5000, TimeUnit.MILLISECONDS)) {
        gracefullyLeaveParticipants(2);
        fail("Waiting for 4 streamPlaying events to happen in total");
        return;
    }

    user.getEventManager().off("streamPlaying");
    log.info("Thread assertions: {}", threadAssertions.toString());
    for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) {
        Assert.assertTrue("Some Event property was wrong", iter.next());
        iter.remove();
    }

    numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
    Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos);
    Assert.assertTrue("Videos were expected to only have audio tracks", user.getEventManager()
            .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), false, true));

    final CountDownLatch latch3 = new CountDownLatch(2);

    // Third publication (audio + video [CAMERA])
    user.getEventManager().on("streamPlaying", (event) -> {
        JsonObject stream = event.get("target").getAsJsonObject().get("stream").getAsJsonObject();
        threadAssertions.add("CAMERA".equals(stream.get("typeOfVideo").getAsString()));
        threadAssertions.add(stream.get("hasAudio").getAsBoolean());
        latch3.countDown();
    });
    user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .change-publisher-btn")).click();
    user.getEventManager().waitUntilEventReaches("streamDestroyed", 4);
    user.getEventManager().waitUntilEventReaches("accessAllowed", 3);
    user.getEventManager().waitUntilEventReaches("streamCreated", 6);
    user.getEventManager().waitUntilEventReaches("streamPlaying", 6);

    if (!latch3.await(8000, TimeUnit.MILLISECONDS)) {
        gracefullyLeaveParticipants(2);
        fail("Waiting for 6 streamPlaying events to happen in total");
        return;
    }

    user.getEventManager().off("streamPlaying");
    log.info("Thread assertions: {}", threadAssertions.toString());
    for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) {
        Assert.assertTrue("Some Event property was wrong", iter.next());
        iter.remove();
    }

    numberOfVideos = user.getDriver().findElements(By.tagName("video")).size();
    Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos);
    Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager()
            .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true));

    gracefullyLeaveParticipants(2);
}

From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java

@Test
@DisplayName("Stream property changed event")
void streamPropertyChangedEventTest() throws Exception {

    Queue<Boolean> threadAssertions = new ConcurrentLinkedQueue<Boolean>();

    setupBrowser("chromeAlternateScreenShare");

    log.info("Stream property changed event");

    WebElement oneToManyInput = user.getDriver().findElement(By.id("one2many-input"));
    oneToManyInput.clear();//from  w  w w. j  av a2 s . co  m
    oneToManyInput.sendKeys("1");

    user.getDriver().findElement(By.id("one2many-btn")).click();
    user.getDriver().findElement(By.className("screen-radio")).click();

    List<WebElement> joinButtons = user.getDriver().findElements(By.className("join-btn"));
    for (WebElement el : joinButtons) {
        el.sendKeys(Keys.ENTER);
    }

    user.getEventManager().waitUntilEventReaches("connectionCreated", 4);
    user.getEventManager().waitUntilEventReaches("accessAllowed", 1);
    user.getEventManager().waitUntilEventReaches("streamCreated", 2);
    user.getEventManager().waitUntilEventReaches("streamPlaying", 2);

    // Unpublish video
    final CountDownLatch latch1 = new CountDownLatch(2);
    user.getEventManager().on("streamPropertyChanged", (event) -> {
        threadAssertions.add("videoActive".equals(event.get("changedProperty").getAsString()));
        threadAssertions.add(!event.get("newValue").getAsBoolean());
        latch1.countDown();
    });
    user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .pub-video-btn")).click();
    user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 2);

    if (!latch1.await(5000, TimeUnit.MILLISECONDS)) {
        gracefullyLeaveParticipants(2);
        fail();
        return;
    }

    user.getEventManager().off("streamPropertyChanged");
    log.info("Thread assertions: {}", threadAssertions.toString());
    for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) {
        Assert.assertTrue("Some Event property was wrong", iter.next());
        iter.remove();
    }

    // Unpublish audio
    final CountDownLatch latch2 = new CountDownLatch(2);
    user.getEventManager().on("streamPropertyChanged", (event) -> {
        threadAssertions.add("audioActive".equals(event.get("changedProperty").getAsString()));
        threadAssertions.add(!event.get("newValue").getAsBoolean());
        latch2.countDown();
    });
    user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .pub-audio-btn")).click();
    user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 4);

    if (!latch2.await(5000, TimeUnit.MILLISECONDS)) {
        gracefullyLeaveParticipants(2);
        fail();
        return;
    }

    user.getEventManager().off("streamPropertyChanged");
    log.info("Thread assertions: {}", threadAssertions.toString());
    for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) {
        Assert.assertTrue("Some Event property was wrong", iter.next());
        iter.remove();
    }

    // Resize captured window
    final CountDownLatch latch3 = new CountDownLatch(2);
    int newWidth = 1000;
    int newHeight = 700;

    final long[] expectedWidthHeight = new long[2];

    user.getEventManager().on("streamPropertyChanged", (event) -> {
        String expectedDimensions = "{\"width\":" + expectedWidthHeight[0] + ",\"height\":"
                + expectedWidthHeight[1] + "}";
        threadAssertions.add("videoDimensions".equals(event.get("changedProperty").getAsString()));
        threadAssertions.add(expectedDimensions.equals(event.get("newValue").getAsJsonObject().toString()));
        latch3.countDown();
    });

    user.getDriver().manage().window().setSize(new Dimension(newWidth, newHeight));

    String widthAndHeight = user.getEventManager().getDimensionOfViewport();
    JSONObject obj = (JSONObject) new JSONParser().parse(widthAndHeight);

    expectedWidthHeight[0] = (long) obj.get("width");
    expectedWidthHeight[1] = (long) obj.get("height");

    System.out.println("New viewport dimension: " + obj.toJSONString());

    user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 6);

    if (!latch3.await(5000, TimeUnit.MILLISECONDS)) {
        gracefullyLeaveParticipants(2);
        fail();
        return;
    }

    user.getEventManager().off("streamPropertyChanged");
    log.info("Thread assertions: {}", threadAssertions.toString());
    for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) {
        Assert.assertTrue("Some Event property was wrong", iter.next());
        iter.remove();
    }

    gracefullyLeaveParticipants(2);
}