小编Ser*_*gey的帖子

针对不同输入数据的Java单元测试

我需要测试一些api.例如,我在类中有多个@Test方法来测试我的功能,在init之前我连接到我的服务的某个url,然后使用它.

如果我在多个网址(不同的服务器环境)上提供服务,我该如何针对不同的服务网址测试此功能?

流:

  1. 由网址初始conncetion
  2. 运行所有测试
  3. 初始由另一个网址conncetion
  4. 运行所有测试(相同)
  5. ...

什么时候只有一个主人我喜欢这个:

public class TestAPI{
    @org.junit.Before
    public void init() {
      service = new Service("www.test.com");
    }
    @org.junit.Test
    public void testA(){
      service.CallA(); 
    }
    @org.junit.Test
    public void testB(){
     service.CallB(); 
    }
}
Run Code Online (Sandbox Code Playgroud)

java junit junit4

9
推荐指数
2
解决办法
9482
查看次数

ConcurrentSkipListMap如何使删除和添加调用原子

我有N个线程添加值和一个删除线程.我正在考虑如何同步添加到现有值列表和删除列表的最佳方法.

我想以下案例是可能的:

 thread 1 checked condition containsKey, and entered in else block
 thread 2 removed the value
 thread 1 try to add value to existing list, and get returns null
Run Code Online (Sandbox Code Playgroud)

我认为我可以使用的唯一方法是通过地图值进行同步,在我们的情况下是添加时和删除时的List

    private ConcurrentSkipListMap<LocalDateTime, List<Task>> tasks = new ConcurrentSkipListMap<>();

    //Thread1,3...N
    public void add(LocalDateTime time, Task task) {
        if (!tasks.containsKey(time)) {
            tasks.computeIfAbsent(time, k -> createValue(task));
        } else {
             //potentially should be synced
            tasks.get(time).add(task);
        }
    }
    private List<Task> createValue(Task val) {
        return new ArrayList<>(Arrays.asList(val));
    }

    //thread 2
   public void remove()
    while(true){
        Map.Entry<LocalDateTime, List<Task>> …
Run Code Online (Sandbox Code Playgroud)

java multithreading java.util.concurrent java-8

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

ZedGraph填充区域

我正在使用ZedGraph控件,并希望在图形函数的一侧填充一些颜色,而另一侧填充其他颜色.

 PointPairList list1 = new PointPairList();
 list1.Add(0, 4);
 list1.Add(4, 0);
 LineItem myCurve = myPane.AddCurve("y(n)", list1, Color.Red, SymbolType.Diamond);

 //This filling bottom side.
 myCurve.Line.Fill = new Fill(Color.White, Color.FromArgb(113, 255, 0, 0), 90F);

 //How to fill the top side?
Run Code Online (Sandbox Code Playgroud)

c# graphics zedgraph

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

Java parallelStream映射错过了记录

我有以下代码,有时行为不确定.例如,我在那里传递3个事件,输出只有两个!你能解释一下这种行为的原因吗?

public List<AbstractTransactionResponse> getEventResponse(final List<AbstractEvent> events){

        List<AbstractTransactionResponse> abstractTransactionResponses = new ArrayList<>();
        events.parallelStream().map(event -> {
            abstractTransactionResponses.add(getEventResponse(event));
            return null;
        }).collect(Collectors.toList());
        return abstractTransactionResponses;
    }
Run Code Online (Sandbox Code Playgroud)

java java-8 java-stream

4
推荐指数
1
解决办法
178
查看次数

如何将2个变量与<c:if>进行比较

我使用的JSP + Spring MVC和JSP页面上,我有一些名单- catListidname,也有一些变化test.我想比较cat.idtest,但不能因为每次运行时有语法错误:

<c:forEach var="cat" items="${catList}" varStatus="i">
  <c:out value="${cat.id}"/>
 <%-- comparison and some action--%>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)

尝试:

<c:if test="${category.id == test}" >
<c:if test="${category.id eq test}" >
<c:if test="${category.id eq ${test}}">
Run Code Online (Sandbox Code Playgroud)

更新:我解决了这个问题,只是服务器重新部署时出错了

java spring jsp jstl spring-mvc

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

超过此主体的最大会话时的Spring安全重定向

所以用户登录- >关闭浏览器- >再次打开浏览器- >出现错误:

HTTP Status 401 - Authentication Failed: Maximum sessions of 1 for this principal exceeded
Run Code Online (Sandbox Code Playgroud)

我需要的是捕获会话无效的事件,删除该用户的所有会话并重定向到正常登录页面

spring security配置:

        <http auto-config="true" use-expressions="true">
                <session-management session-fixation-protection="migrateSession">
                    <concurrency-control max-sessions="1" error-if-maximum-exceeded="true"/>
                </session-management>   
                <intercept-url pattern="/login" access="hasRole('ROLE_ANONYMOUS')" requires-channel="any"/> 

    <!--<custom-filter after="CONCURRENT_SESSION_FILTER" ref="sessionExpiration" /> -->
    <!-- .... -->

        </http>

<beans:bean id="sessionExpiration" class="com.test.security.SessionExpirationFilter">
    <beans:property name="expiredUrl">
            <beans:value>/login</beans:value>
        </beans:property>
 </beans:bean>
Run Code Online (Sandbox Code Playgroud)

我试图实现一些过滤器,但它总是显示会话为空:

public class SessionExpirationFilter implements Filter, InitializingBean {
    private String expiredUrl;

    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security

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

c#字符串分析

我有一个字符串,例如":)text:)text :) :-) word :-("我需要将它附加到文本框(或其他地方),条件:

而不是':)',':-('等需要调用输入特定符号的函数

我用有限状态机来解决存在的解决方案,但是如何实现它不知道.等待建议.

更新: ":)文字:)文字:) :-)字:-(" => 当我们见面':)'wec所有功能微笑(":)")它在文本框上显示图像

更新:我喜欢与代表和Regex.Replace的想法.我可以当遇到':)'发送到委托参数':)'和遇见':('其他参数.

更新:找到解决方案转换为char并将每个符号比较为':)'如果相等则调用smile(':)')

.net c# programming-languages

0
推荐指数
1
解决办法
1271
查看次数