Example usage for org.springframework.util Assert state

List of usage examples for org.springframework.util Assert state

Introduction

In this page you can find the example usage for org.springframework.util Assert state.

Prototype

@Deprecated
public static void state(boolean expression) 

Source Link

Document

Assert a boolean expression, throwing an IllegalStateException if the expression evaluates to false .

Usage

From source file:org.tommy.stationery.moracle.core.client.load.StompWebSocketLoadTestClient.java

public static void main(String[] args) throws Exception {

    // Modify host and port below to match wherever StompWebSocketServer.java is running!!
    // When StompWebSocketServer starts it prints the selected available

    String host = "localhost";
    if (args.length > 0) {
        host = args[0];//  w ww.  ja  v a 2 s  .  co m
    }

    int port = 59984;
    if (args.length > 1) {
        port = Integer.valueOf(args[1]);
    }

    String url = "http://" + host + ":" + port + "/home";
    logger.debug("Sending warm-up HTTP request to " + url);
    HttpStatus status = new RestTemplate().getForEntity(url, Void.class).getStatusCode();
    Assert.state(status == HttpStatus.OK);

    final CountDownLatch connectLatch = new CountDownLatch(NUMBER_OF_USERS);
    final CountDownLatch subscribeLatch = new CountDownLatch(NUMBER_OF_USERS);
    final CountDownLatch messageLatch = new CountDownLatch(NUMBER_OF_USERS);
    final CountDownLatch disconnectLatch = new CountDownLatch(NUMBER_OF_USERS);

    final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();

    Executor executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
    org.eclipse.jetty.websocket.client.WebSocketClient jettyClient = new WebSocketClient(executor);
    JettyWebSocketClient webSocketClient = new JettyWebSocketClient(jettyClient);
    webSocketClient.start();

    HttpClient jettyHttpClient = new HttpClient();
    jettyHttpClient.setMaxConnectionsPerDestination(1000);
    jettyHttpClient.setExecutor(new QueuedThreadPool(1000));
    jettyHttpClient.start();

    List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(webSocketClient));
    transports.add(new JettyXhrTransport(jettyHttpClient));

    SockJsClient sockJsClient = new SockJsClient(transports);

    try {
        URI uri = new URI("ws://" + host + ":" + port + "/stomp");
        WebSocketStompClient stompClient = new WebSocketStompClient(uri, null, sockJsClient);
        stompClient.setMessageConverter(new StringMessageConverter());

        logger.debug("Connecting and subscribing " + NUMBER_OF_USERS + " users ");
        StopWatch stopWatch = new StopWatch("STOMP Broker Relay WebSocket Load Tests");
        stopWatch.start();

        List<ConsumerStompMessageHandler> consumers = new ArrayList<>();
        for (int i = 0; i < NUMBER_OF_USERS; i++) {
            consumers.add(new ConsumerStompMessageHandler(BROADCAST_MESSAGE_COUNT, connectLatch, subscribeLatch,
                    messageLatch, disconnectLatch, failure));
            stompClient.connect(consumers.get(i));
        }

        if (failure.get() != null) {
            throw new AssertionError("Test failed", failure.get());
        }
        if (!connectLatch.await(5000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all users connected, remaining: " + connectLatch.getCount());
        }
        if (!subscribeLatch.await(5000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all users subscribed, remaining: " + subscribeLatch.getCount());
        }

        stopWatch.stop();
        logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis");

        logger.debug("Broadcasting " + BROADCAST_MESSAGE_COUNT + " messages to " + NUMBER_OF_USERS + " users ");
        stopWatch.start();

        ProducerStompMessageHandler producer = new ProducerStompMessageHandler(BROADCAST_MESSAGE_COUNT,
                failure);
        stompClient.connect(producer);

        if (failure.get() != null) {
            throw new AssertionError("Test failed", failure.get());
        }
        if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) {
            for (ConsumerStompMessageHandler consumer : consumers) {
                if (consumer.messageCount.get() < consumer.expectedMessageCount) {
                    logger.debug(consumer);
                }
            }
        }
        if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all handlers received every message, remaining: " + messageLatch.getCount());
        }

        producer.session.disconnect();
        if (!disconnectLatch.await(5000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all disconnects completed, remaining: " + disconnectLatch.getCount());
        }

        stopWatch.stop();
        logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis");

        System.out.println("\nPress any key to exit...");
        System.in.read();
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        webSocketClient.stop();
        jettyHttpClient.stop();
    }

    logger.debug("Exiting");
    System.exit(0);
}

From source file:org.eclipse.swordfish.core.configuration.xml.SaxParsingPrototype.java

private static Map<String, String> flatten(Map<String, List<String>> props) {
    Map<String, String> ret = new HashMap<String, String>(props.size());
    for (String key : props.keySet()) {
        List<String> values = props.get(key);
        Assert.state(values.size() > 0);
        if (values.size() == 1) {
            ret.put(key, values.get(0));
        } else {/*from  w w w . j ava 2  s . co m*/
            for (int i = 0; i < values.size(); i++) {
                ret.put(key + "{" + (i + 1) + "}", values.get(i));
            }
        }
    }
    return ret;
}

From source file:walkAlong.TrueFalseTest.java

@Test
public void getAnswerT() {
    Assert.state(objTF.returnFalse());
}

From source file:io.github.hzpz.spring.boot.autoconfigure.mongeez.DoNotExecuteMongeezPostProcessor.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String[] mongeezBeanNames = beanFactory.getBeanNamesForType(Mongeez.class);
    Assert.state(mongeezBeanNames.length == 1);
    BeanDefinition beanDefinition = beanFactory.getBeanDefinition(mongeezBeanNames[0]);
    Assert.state(beanDefinition instanceof RootBeanDefinition);
    ((RootBeanDefinition) beanDefinition).setInitMethodName(null);
}

From source file:org.ohdsi.webapi.test.CohortAnalysisServiceIT.java

private void assertOk(final ResponseEntity<?> entity) {
    Assert.state(entity.getStatusCode() == HttpStatus.OK);
}

From source file:com.joshlong.esb.springintegration.modules.social.twitter.TwitterTweetSendingMessageHandler.java

public void afterPropertiesSet() throws Exception {
    Assert.state(null != type);

    if (twitter == null) {
        Assert.state(!StringUtils.isEmpty(username));
        Assert.state(!StringUtils.isEmpty(password));

        twitter = new Twitter();
        twitter.setUserId(username);//from  w ww  . j a  v a2s .com
        twitter.setPassword(password);
    } else { // it isnt null, in which case it becomes canonical memory
        setPassword(twitter.getPassword());
        setUsername(twitter.getUserId());
    }
}

From source file:org.ohdsi.webapi.test.CohortAnalysisServiceIT.java

private void assertJobExecution(final JobExecutionResource execution) {
    Assert.state(execution != null);
    Assert.state(execution.getExecutionId() != null);
    Assert.state(execution.getJobInstanceResource().getInstanceId() != null);
}

From source file:com.joshlong.esb.springintegration.modules.social.twitter.TwitterMessageSource.java

public void afterPropertiesSet() throws Exception {
    logger.debug("after properties set for TwitterMessageSource!!");

    if (twitter == null) {
        Assert.state(!StringUtils.isEmpty(userId));
        Assert.state(!StringUtils.isEmpty(password));

        twitter = new Twitter();
        twitter.setUserId(userId);//from   w  w  w  .  ja  v  a 2 s.co m
        twitter.setPassword(password);
    } else { // it isnt null, in which case it becomes canonical memory
        setPassword(twitter.getPassword());
        setUserId(twitter.getUserId());
    }

    cachedStatuses = new ConcurrentLinkedQueue<Tweet>();
    lastStatusIdRetreived = -1;
}

From source file:com.github.fharms.route.JokeDAO.java

@SuppressWarnings("unused")
public void increaseDisplayCount(Exchange exchange) {
    //let's just test for fun that the Camel EntityManager is the same as bean entity manager
    EntityManager camelEntityManager = exchange.getIn()
            .getHeader(CamelEntityManagerHandler.CAMEL_ENTITY_MANAGER, EntityManager.class);
    Assert.state(em.equals(camelEntityManager));
    Joke joke = exchange.getIn().getBody(Joke.class);
    joke.setCount(joke.getCount() + 1);//from  w  w  w.  j  a v  a 2 s .c o m
    exchange.getIn().setBody(joke);
}

From source file:com.tcz.api.config.captcha.CaptchaEngine.java

/**
 * ?//from   w ww . j  a  va2 s.co m
 */
public void afterPropertiesSet() throws Exception {
    Assert.state(imageWidth > 0);
    Assert.state(imageHeight > 0);
    Assert.state(minFontSize > 0);
    Assert.state(maxFontSize > 0);
    Assert.state(minWordLength > 0);
    Assert.state(maxWordLength > 0);
    Assert.hasText(charString);

    Font[] fonts = new Font[] { new Font("Arial", Font.BOLD, maxFontSize),
            new Font("Bell", Font.BOLD, maxFontSize), new Font("Credit", Font.BOLD, maxFontSize),
            new Font("Impact", Font.BOLD, maxFontSize) };
    FontGenerator fontGenerator = new RandomFontGenerator(minFontSize, maxFontSize, fonts);
    BackgroundGenerator backgroundGenerator = StringUtils.isNotEmpty(backgroundImagePath)
            ? new FileReaderRandomBackgroundGenerator(imageWidth, imageHeight,
                    servletContext.getRealPath(backgroundImagePath))
            : new FunkyBackgroundGenerator(imageWidth, imageHeight);
    TextPaster textPaster = new RandomTextPaster(minWordLength, maxWordLength, Color.LIGHT_GRAY);
    CaptchaFactory[] captchaFactories = new CaptchaFactory[] {
            new GimpyFactory(new RandomWordGenerator(charString),
                    new ComposedWordToImage(fontGenerator, backgroundGenerator, textPaster)) };
    super.setFactories(captchaFactories);
}