<commit_before>/*
 * Copyright 2006 ThoughtWorks, Inc.
 *
 *  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 org.openqa.selenium;

import org.openqa.selenium.server.SeleniumCommandTimedOutException;
import org.openqa.selenium.server.SingleEntryAsyncQueue;
import org.openqa.selenium.server.browserlaunchers.*;

import junit.framework.TestCase;

public class QueueTest extends TestCase {
    SingleEntryAsyncQueue q;
    
    class QTestThread extends Thread {
        private Object objToPut;

        public void run() {
            System.out.println("QTestThread.run putting " + objToPut);
            q.put(objToPut);
            System.out.println("QTestThread.run returned from putting " + objToPut);
        }

        public void willPut(String s) {
            objToPut = s;
        }
    }
    
    public void setUp() {
        q = new SingleEntryAsyncQueue();
    }
    
    public void testClearHungGetter() throws Exception {
        new Thread() {
            public void run() {
                boolean exceptionSeen = false;
                try {
                    q.get();
                }
                catch (RuntimeException e) {
                    exceptionSeen = true;
                }
                catch (Throwable e) {
                    fail("got an unexpected exception: " + e);
                }
                assertTrue(exceptionSeen);
            }
        }.start();
        AsyncExecute.sleepTight(300);    // give getter thread a chance to go wait on the queue
        q.clear();
    }
    
    class PuttingThread extends Thread {
        public String failureMessage = "not set yet";
        public void run() {
            try {
                q.put("abc");   // this one executes and immediately returns
                q.put("xyz");   // this one will wait for q.size to be 1 before returning
            }
            catch (RuntimeException e) {
                failureMessage = "Putting thread saw unexpected failure: " + e;
                return;
            }
            catch (Throwable e) {
                failureMessage = "Putting thread saw unexpected throw: " + e;
                return;
            }
            failureMessage = "ok";
        }
    };
    
    public void testClearHungPutter() throws Exception {
        PuttingThread t = new PuttingThread(); 
        t.start();
        AsyncExecute.sleepTight(1000);    // give getter thread a chance to go wait on the queue
        q.clear();
        t.join();
        assertEquals("ok", t.failureMessage);
    }
    
    public void testGetFromEmptyQueue() throws Exception {
        q.setTimeout(0);
        boolean seleniumCommandTimedOutExceptionSeen = false;
        try {
            q.get();
        }
        catch (SeleniumCommandTimedOutException e) {
            seleniumCommandTimedOutExceptionSeen = true;
        }
        assertEquals(true, seleniumCommandTimedOutExceptionSeen);
    }
        
    public void testTrivial() {
        q.put("hi");
        String s = (String) q.get();
        assertEquals("hi", s);
    }
    public void testTrivialx2() {
        q.put("hi");
        q.get();
        q.put("there");
        String s = (String) q.get();
        assertEquals("there", s);
    }<commit_msg>rm tests which require a queue which can handle multiple entries<commit_after>/*
 * Copyright 2006 ThoughtWorks, Inc.
 *
 *  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 org.openqa.selenium;

import junit.framework.TestCase;

import org.openqa.selenium.server.SeleniumCommandTimedOutException;
import org.openqa.selenium.server.SingleEntryAsyncQueue;
import org.openqa.selenium.server.browserlaunchers.AsyncExecute;

public class QueueTest extends TestCase {
    SingleEntryAsyncQueue q;
    
    class QTestThread extends Thread {
        private Object objToPut;

        public void run() {
            System.out.println("QTestThread.run putting " + objToPut);
            q.put(objToPut);
            System.out.println("QTestThread.run returned from putting " + objToPut);
        }

        public void willPut(String s) {
            objToPut = s;
        }
    }
    
    public void setUp() {
        q = new SingleEntryAsyncQueue();
    }
    
    public void testClearHungGetter() throws Exception {
        new Thread() {
            public void run() {
                try {
                    q.get();
                }
                catch (Throwable e) {
                    fail("got an unexpected exception: " + e);
                }
           }
        }.start();
        AsyncExecute.sleepTight(300);    // give getter thread a chance to go wait on the queue
        q.reset();
    }
    
    public void testGetFromEmptyQueue() throws Exception {
        q.setTimeout(0);
        boolean seleniumCommandTimedOutExceptionSeen = false;
        try {
            q.get();
        }
        catch (SeleniumCommandTimedOutException e) {
            seleniumCommandTimedOutExceptionSeen = true;
        }
        assertEquals(true, seleniumCommandTimedOutExceptionSeen);
    }
        
    public void testTrivial() {
        q.put("hi");
        String s = (String) q.get();
        assertEquals("hi", s);
    }
    public void testTrivialx2() {
        q.put("hi");
        q.get();
        q.put("there");
        String s = (String) q.get();
        assertEquals("there", s);
    }
{'fraction_non_alphanumeric': 0.09039812646370024, 'fraction_numerical': 0.004839968774395004, 'mean_word_length': 1.9466421343146274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3628884', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1680, 'n_words': 512}