首页 \ 问答 \ 使用ConcurrentSkipListMap的并发测试队列(Concurrent Testing Queue using ConcurrentSkipListMap)

使用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
更新时间:2023-01-16 08:01

最满意答案

这是一个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.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。