使用ConcurrentSkipListMap的并发测试队列(Concurrent Testing Queue using ConcurrentSkipListMap)
我最近不得不完成其中一个面试编码练习。 基本上它需要实现一个消息队列类:
- 根据传入消息中的优先级字段维护项目。
- 消息可以通过message.priorityField值范围在高,中,低三个优先级类别之一中控制。
- 有一个getSize和isEmpty方法。
- 有一个地方(消息)方法。
- 有一个删除方法。
- 有getFront()方法(返回最高优先级的消息)
我最后没有详细介绍的是实现一个MessageQueue类,它在内部使用ConcurrentSkipListMap(一个并发和有序的映射)来保存消息。
我还实现了一个基本的JUnit测试用例,用于测试基本的业务需求。
现在因为它是一个消息传递队列,因此消息可以同时进入,我需要测试实现的当前方面。
我现在越来越接近问题的核心了。
我的想法是,当单个线程与实现交互时,基本的JUnit测试用例应该验证代码是否有效。
然后,我实现了一个并发测试用例,该测试用例应验证实现的当前方面。
现在问题是:我应该测试哪些并发方面?
我唯一能想到的是让多个生产者线程在队列中注入方法,以及多个消费者线程来删除消息(通过getFront())。 这里验证的是队列中的任何消息最终都会消失。
但那够了吗? 可以在这里测试哪些其他并发方面?
另外值得注意的是,我已经提交了解决方案,所以无论你提出什么建议都不会对我申请这份工作的机会产生任何影响。
I recently had to complete one of these job interview coding exercises. Basically it required implementing a message queue class that:
- maintains items based on a priority field in the incoming message.
- the message can be in one of three priority categories high, medium, low controlled via message.priorityField value range.
- has a getSize and isEmpty methods.
- has a place(message) method.
- has a remove method.
- has getFront() method (which returns highest priority message)
What I did in the end without going into too much detail is implement a MessageQueue class that internally uses ConcurrentSkipListMap (a concurrent and ordered map) to hold the messages.
I also implemented a basic JUnit test case that tests for basic business requirements.
Now as its a messaging queue and hence messages can come in concurrently of course I need to test the occurrent aspect of the implementation.
I'm getting closer to the heart of the question now.
My thinking is that the basic JUnit test case should verify the code works when a single thread is interacting with the implementation.
I then implemented a concurrent test case which should verify the occurrent aspect of the implementation.
Now here is the question: What concurrent aspects should I be testing for?
The only thing I can think of is having multiple producer threads that inject methods in the queue and multiple consumer threads that remove the messages (via getFront()) . What is being verified here is that whatever messages went in the queue will eventually come out.
But is that enough? what other concurrent aspects could be tested for here?
Also worth noting that I have already submitted the solution so whatever you suggested will not have any impact on my chances for this job I applied for.
原文:https://stackoverflow.com/questions/14618982
最满意答案
这是一个Maven-mananged项目。 简单地说:
mvn package mvn tomcat:run
Maven将使用您的webapp启动嵌入式Tomcat。
This is a Maven-mananged project. Simply do:
mvn package mvn tomcat:run
Maven will start an embedded Tomcat with your webapp.
相关问答
更多-
除了IIS和Apache,还有没有其它的服务器程序[2022-05-09]
tomcat -
我的猜测是你的类路径中存在一些问题。 也许,您可能在类路径或WEB-INF / lib中有两个不同版本的球衣 My guess is that there is something wrong with tha jars in your classpath. Probably, you may have two different versions of jersey on your classpath or in WEB-INF/lib
-
您正在寻找JMX。 有关更多信息,请参阅FAQ中的Tomcat 监控页面 。 使用JMX进行连接以及如何获取各种值比SO可以覆盖的适当答案复杂得多,所以请看一下。 我还在ApacheCon 2015上发表了关于使用JMX监视Tomcat的演示文稿,其中介绍了如何使用外部工具进行监视,但是会为您提供一些有关如何查找所需数据的良好信息(甚至可以介绍一些可用的数据从其他工具取样)。 You are looking for JMX. Have a look at Tomcat's monitoring page f ...
-
这是一个Maven-mananged项目。 简单地说: mvn package mvn tomcat:run Maven将使用您的webapp启动嵌入式Tomcat。 This is a Maven-mananged project. Simply do: mvn package mvn tomcat:run Maven will start an embedded Tomcat with your webapp.
-
无法将web应用程序部署到debian虚拟服务器上的tomcat7(Unable to deploy web application to tomcat7 on debian virtual server)[2021-12-29]
你应该在不依赖tomcat7-maven-plugin中有tomcat7-maven-plugin ,请参阅用法页面。 从依赖项中删除并尝试 You should have tomcat7-maven-plugin in plugins not in dependencies see the usage page. Remove from dependencies and try -
我认为您正在尝试使用您的基础架构来解决您的问题,而不是在应该解决的情况下使用您的应用程序。如果要求是在某段时间内没有应用程序可用,这是业务需求,请编写解决方案它。 例如,如果登录超出指定的时间段,则可以不允许登录,然后向用户显示消息。 可以使用处理程序拦截现有会话,然后使会话无效以强制重新登录。 另一种解决方案是在服务器上运行cron作业,该作业在指定时间停止Tomcat并再次启动它。 这是不可取的,因为您的用户不会知道操作时间,并且很可能假设出现了问题。 Finally i have implemente ...
-
1)如果我将所有静态内容放在Apache http服务器中,那么我可以从project-web中删除所有静态内容吗? 是。 这两个项目都可以单独存在吗? 他们可以,但webapp中的东西(应该)永远不会被访问,那么重点是什么? 2)项目的静态内容将在Apache http web服务器和web应用程序中部署在Apache tomcat中,此外这两个服务器都将在不同的VM机器中。 tomcat中的Web应用程序如何从不同VM机器中的Apache Web服务器访问静态内容?(例如jsp如何指向图像?) weba ...
-
任何一个都将满足您的要求。 Tomcat需要安装 - 或者可以嵌入; 感谢Jayan的纠正。 Jetty可以嵌入或以独立模式运行。 在此基础上选择。 但是如果你要设置一个集中式服务器,你可能会考虑Netty而不是两者。 NIO可能会帮助您提高吞吐量。 根据下面的Joakim Erdfelt,Jetty也使用了NIO。 感谢您的教育和纠正。 我不知道Tomcat是否效仿。 Either one will satisfy your stated requirements. Tomcat will require ...
-
所以,这是我的问题的解决方案: 将插件更改为tomcat7-maven-plugin:
org.apache.tomcat.maven tomcat7-maven-plugin 2.2 ... -
如何在apache web服务器中配置tomcat java应用程序?(How to configure tomcat java application in apache web server?)[2023-02-21]
我自己解决了这个问题。 我之前提到的配置没有问题..ServerName domain.com ProxyRequests Off ProxyPreserveHost On Order deny,allow Allow from all ProxyPass / http://localhost:8080/app_name ProxyPassRe ...