小编Rob*_*oks的帖子

Spring JUnit测试错误

我尝试运行Spring JUnit测试时收到以下错误.我只是想熟悉使用Spring Framework创建JUnits.

JUnit类:

package org.xxx.springdao.mongo_datadictionary;

import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.xxx.springdao.mongo_datadictionary.SimpleSpringApp;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class SpringJunitTest {


    @Test
    public void testSpringTest() {
        SimpleSpringApp test = new SimpleSpringApp();
        assertNotNull("Success", test);
    }

}
Run Code Online (Sandbox Code Playgroud)

SpringJunitTest-context.xml中:

<pre>

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mongo="http://www.springframework.org/schema/data/mongo"
        xsi:schemaLocation="http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              http://www.springframework.org/schema/data/mongo
              http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
              http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    </beans>

</block>
Run Code Online (Sandbox Code Playgroud)

pom.xml中:

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons-core</artifactId>
        <version>1.2.0.BUILD-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>1.0.0.M5</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId> …
Run Code Online (Sandbox Code Playgroud)

spring junit4

35
推荐指数
1
解决办法
5万
查看次数

java.nio Selectors和SocketChannel用于继续流式传输

我目前正在为一个应用程序使用java.nio.channel.Selectors和SocketChannels,该应用程序将打开1对多连接以继续流式传输到服务器.我的应用程序有三个线程:StreamWriteWorker - 对SocketChannel执行写操作,StreamReadWorker - 从缓冲区读取字节并解析内容,StreamTaskDispatcher - 执行Selector对readyOps的选择,并为工作线程调度新的runnable.

问题 - 选择器的选择方法上的调用仅在第一次调用时返回值> 0(有效的readyOps); 我能够在所有就绪通道上执行一次写入和发送数据,但是Selector选择方法的以下所有调用都返回0.

问题:每次读/写后我是否需要在SocketChannel上调用close(我希望不是!)?如果不是什么原因可能导致SocketChannel无法用于任何读/写操作?

对不起,我不能发布代码,但我希望我已经清楚地解释了这个问题,以便有人帮忙.我已经搜索了答案,我看到你关闭后不能重用SocketChannel连接,但我的频道不应该关闭,服务器永远不会收到EOF流结果.

我取得了一些进展,并发现由于json解析错误,服务器应用程序上没有发生写操作.所以现在我的客户端应用程序代码上的SocketChannel在处理读取操作后就可以进行另一次写操作了.我想这是SocketChannels的TCP特性.但是,SocketChannel不可用于服务器应用程序端的另一个读取操作.这是SocketChannels的正常行为吗?在读取操作之后是否需要在客户端关闭连接并建立新连接?

这是我想要做的代码示例:

package org.stream.socket;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.util.HashMap;
import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.commons.lang3.RandomStringUtils;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.stream.JsonToken;

public class ClientServerTest {

    private LinkedBlockingQueue<byte[]> dataQueue = new LinkedBlockingQueue<byte[]>();
    private ExecutorService …
Run Code Online (Sandbox Code Playgroud)

java nio

6
推荐指数
1
解决办法
9887
查看次数

d3js线条图的平滑线条

我目前正在研究基于刷子时间窗选择更新的d3js图表.我遇到的问题是主图上的线看起来很不稳定.我已经改变了插值以使用不同的类型,以及使用张力属性,但我似乎无法获得流畅的线条.有没有人有任何想法?

var data = new TLSampleDataContainer()
,   keyToEntries = data.keyToEntries
,   keys = data.keyset
,   pageSize = data.pageSize;

// Visual attributes 
var tl = {
        times : data.timeEntries,       
        xTicks : function(start, end){
            var min = start.getTime()
            ,   max = end.getTime()
            ,   range;

            if(max-min <= CONSTANTS.TIME.HOURS.SCALE_FACTOR){
                var totalHours = d3.round((max-min)/3600000);
                var scale = Math.ceil(totalHours/12);
                return d3.time.hours(start, end, scale);
            }

            if(max-min <= CONSTANTS.TIME.DAYS.SCALE_FACTOR){
                var totalDays = d3.round((max-min)/86400000);
                var scale = Math.ceil(totalDays/7);
                range = d3.time.days(start, end, scale);
                return range;
            }

            if(max-min <= CONSTANTS.TIME.WEEKS.SCALE_FACTOR){ …
Run Code Online (Sandbox Code Playgroud)

linechart d3.js

3
推荐指数
1
解决办法
3597
查看次数

标签 统计

d3.js ×1

java ×1

junit4 ×1

linechart ×1

nio ×1

spring ×1