Setac: A Phased Deterministic Testing Framework for Scala Actors

Slides:



Advertisements
Similar presentations
MicroKernel Pattern Presented by Sahibzada Sami ud din Kashif Khurshid.
Advertisements

Lecture 12: MapReduce: Simplified Data Processing on Large Clusters Xiaowei Yang (Duke University)
Impossibility of Distributed Consensus with One Faulty Process
CHESS: A Systematic Testing Tool for Concurrent Software CSCI6900 George.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
An introduction to F# (part 2) Bogdan Brinzarea-Iamandi Banca Romaneasca 25 February 2010.
Concurrency, Threads, and Events Robbert van Renesse.
Parrot: A Practical Runtime for Deterministic, Stable, and Reliable threads HEMING CUI, YI-HONG LIN, HAO LI, XINAN XU, JUNFENG YANG, JIRI SIMSA, BEN BLUM,
Distributed Programming in Scala with APGAS Philippe Suter, Olivier Tardieu, Josh Milthorpe IBM Research Picture by Simon Greig.
Scala Actors -Terrance Dsilva.  Thankfully, Scala offers a reasonable, flexible approach to concurrency  Actors aren’t a concept unique to Scala.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.
Austin Java Users Group developerWorks article – µActor Library BARRY FEIGENBAUM, PH. D. 02/26/13.
15-740/ Oct. 17, 2012 Stefan Muller.  Problem: Software is buggy!  More specific problem: Want to make sure software doesn’t have bad property.
Analysis of Concurrent Software Models Using Partial Order Views Qiang Sun, Yuting Chen,
© 2006 IBM Corporation Agile Planning Web UI. © 2006 IBM Corporation Agenda  Overview of APT Web UI  Current Issues  Required Infrastructure  API.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
Title Line Subtitle Line Top of Content Box Line Top of Footer Line Left Margin LineRight Margin Line Top of Footer Line Top of Content Box Line Subtitle.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Title Line Subtitle Line Top of Content Box Line Top of Footer Line Left Margin LineRight Margin Line Top of Footer Line Top of Content Box Line Subtitle.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
CS533 - Concepts of Operating Systems 1 Threads, Events, and Reactive Objects - Alan West.
Source Level Debugging of Parallel Programs Roland Wismüller LRR-TUM, TU München Germany.
2/20/2016 EEC492/693/793 - iPhone Application Development 12/20/2016 EEC492/693/793 - iPhone Application Development 1 EEC-492/693/793 iPhone Application.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
Reachability Testing of Concurrent Programs1 Reachability Testing of Concurrent Programs Richard Carver, GMU Yu Lei, UTA.
Testing Concurrent Programs Sri Teja Basava Arpit Sud CSCI 5535: Fundamentals of Programming Languages University of Colorado at Boulder Spring 2010.
CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.
Parallel Programming Models EECC 756 David D. McGann 18 May, 1999.
Pitfalls: Time Dependent Behaviors CS433 Spring 2001 Laxmikant Kale.
Lecture 3 – MapReduce: Implementation CSE 490h – Introduction to Distributed Computing, Spring 2009 Except as otherwise noted, the content of this presentation.
Java Thread Programming
RubyConf 2012 Artūras 'arturaz' Šlajus
Tom Van Cutsem, Vrije Universiteit Brussel
Last Class: Introduction
REAL-TIME OPERATING SYSTEMS
Efficient Evaluation of XQuery over Streaming Data
Introduction Edited by Enas Naffar using the following textbooks: - A concise introduction to Software Engineering - Software Engineering for students-
The Mach System Sri Ramkrishna.
Prof. Leonardo Mostarda University of Camerino
CPE555A: Real-Time Embedded Systems
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
CSE 775 – Distributed Objects Submitted by: Arpit Kothari
Chapter 8 – Software Testing
Parallel Programming By J. H. Wang May 2, 2017.
Testing and Debugging.
Eng Computation & Data Science.
Chapter 4: Threads.
Threads and Cooperation
Introduction Edited by Enas Naffar using the following textbooks: - A concise introduction to Software Engineering - Software Engineering for students-
Chapter 4: Threads.
Threads and Data Sharing
Transactional Memory Semaphores, monitors, and conditional critical regions all suffer from limitations based on lock semantics Naïve synchronization may.
End-of-Term Winter Progress Report
MPI-Message Passing Interface
Model Checking for an Executable Subset of UML
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Setac: A Phased Deterministic Testing Framework for Scala Actors
Distributed Algorithms
Background and Motivation
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 4: Threads.
Foundations and Definitions
GPU Scheduling on the NVIDIA TX2:
MapReduce: Simplified Data Processing on Large Clusters
Presentation transcript:

Setac: A Phased Deterministic Testing Framework for Scala Actors Samira Tasharofi, Milos Gligoric, Darko Marinov, and Ralph Johnson

Setac Testing Framework Background Two approaches for parallel programming Shared-memory Do not scale with the number of cores Cannot be applied for distributed systems Message-passing Best solution for distributed Systems Can scale with the number of cores Actor model A model for message-passing programming Supported by many libraries and languages Scala, Erlang, C#, C++, Groovy(java-based), etc. Setac Testing Framework 11/9/2018

Setac Testing Framework Actor Model Actor is a computational entity with a mail box and local state Deliver a message Append the message to the mail box Process a message Extract a message from the mail box and execute that Determined by message handler In response to a message it processes: Changes its local state Sends messages to other actors Creates new actors Setac Testing Framework 11/9/2018

Setac Testing Framework Actors in Scala Package scala.actors in Scala library Developed by Philipp Haller Features Synchronous and asynchronous communication Dynamic creation/destroying of actors Exception handling Remote actors Customization of the thread pool executing actors Setac Testing Framework 11/9/2018 Setac Testing Framework

Setac Testing Framework Question How to test actor systems? Setac Testing Framework 11/9/2018

Setac Testing Framework Problems Schedule is a source of non-determinism in concurrent programs Shared memory: order of accesses Message-passing: order of messages The output of the program might be different for a given input depending on the schedule The bugs may only show up during some specific schedules Systematic exploration can lead to state space explosion Asynchronous events don not have instant effects Setac Testing Framework 11/9/2018

Example: BoundedBuffer class BoundedBuffer(maxSize: Int) extends Actor { var content = new Array[Int](size) var head, tail, curSize = 0 start override def act() = loop { react { case Put(x) if (curSize < maxSize) => { content(tail) = x tail = (tail + 1) % size curSize += 1 } case Get if (curSize > 0) => { val r = content(head) head = (head + 1) % size curSize -= 1 reply(r) class Producer(buf: Actor) extends Actor { start override def act() = loop { react { case Produce(values) => values.foreach(v => buf ! Put(v)) } class Consumer(buf: Actor) extends Actor { var token = -1 start override def act() = loop { react { case Consume(count) => for (i <- 0 to count-1) token = (buf !? Get).asInstanceOf[Int] } Setac Testing Framework 11/9/2018 Setac Testing Framework

Setac Testing Framework BufferTest producer Put(4), Put(5) class BufferTest { @Test def testBuffer() { val buf = new BoundedBuffer(1) val consumer = new Consumer(buf) val producer = new Producer(buf) producer ! Produce(List(4, 5)) consumer ! Consume(2) // consumer should receive 4 and 5 assert(… ) } buffer(1) Get, Get 4, 5 consumer Setac Testing Framework 11/9/2018

Setac Testing Framework Buggy BoundedBuffer class BoundedBuffer(maxSize: Int) extends Actor { var content = new Array[Int](size) var head, tail, curSize = 0 start override def act() = loop { react { case Put(x) if (curSize maxSize) => { content(tail) = x tail = (tail + 1) % size curSize += 1 } case Get if (curSize > 0) => { val r = content(head) head = (head + 1) % size curSize -= 1 reply(r) Bug < <= A buffer with capacity of one. Setac Testing Framework 11/9/2018 Setac Testing Framework

Buggy BoundedBuffer: Schedules in BufferTest class BoundedBuffer(maxSize: Int) extends Actor { var content = new Array[Int](size) var head, tail, curSize = 0 start override def act() = loop { react { case Put(x) if (curSize maxSize) => { content(tail) = x tail = (tail + 1) % size curSize += 1 } case Get if (curSize > 0) => { val r = content(head) head = (head + 1) % size curSize -= 1 reply(r) consumer producer buffer(1) Put(4) <= Get 4 Put(5) 5 Get Error! 5 5 Setac Testing Framework 11/9/2018 Setac Testing Framework

Correct BoundedBuffer: Checking Assertions in Test class BoundedBuffer(maxSize: Int) extends Actor { var content = new Array[Int](size) var head, tail, curSize = 0 start override def act() = loop { react { case Put(x) if (curSize < maxSize) => { content(tail) = x tail = (tail + 1) % size curSize += 1 } case Get if (curSize > 0) => { val r = content(head) head = (head + 1) % size curSize -= 1 reply(r) class SimpleBufferTest { @Test def testBuffer() { val buf = new BoundedBuffer(1) buf ! Put(4) assert(buf.curSize == 1) } Fails!! buffer Put(4) … mailbox content, head, tail, curSize local state Fails!! assert Setac Testing Framework 11/9/2018 Setac Testing Framework

Testing Actor Programs Problems: How to write unit tests for Actor programs while controlling the schedule? How to check assertions at appropriate times? Current Solutions: Using synchronization constructs, e.g. Latches and Barriers Using Thread.sleep Setac Testing Framework 11/9/2018

BufferTest: A Test Schedule Consumer Producer BoundedeBuffer(1) Phase 1 Get Check assertions Put(4) 4 Phase 2 Put(5) Check assertions Get Phase 3 5 Check assertions Setac Testing Framework 11/9/2018 Setac Testing Framework

Traditional: BufferTest class BufferTest { @Test def testBuffer() { val putLatch = new CountDownLatch(2) val getLatch = new CountDownLatch(2) val buf = new BoundedBuffer(1, putLatch, getLatch) val consumeLatch = new CountDownLatch(1) val consumer = new Consumer(buf, consumeLatch) val producer = new Producer(buf) //Phase 1 consumer ! Consume(1) consumeLatch.await() Thread.sleep(1000) assert(consumer.getState == State.Blocked && buf.curSize == 0) // … } consumer producer buffer(1) Get Phase 1 class Consumer(buf: Actor, consumeLatch: CountDownLatch) extends Actor { var token = -1 start override def act() = loop { react { case Consume(count) => consumeLatch.countDown() for (i <- 0 to count-1) token = (buf !? Get).asInstanceOf[Int] } Setac Testing Framework 11/9/2018

Traditional: BufferTest (cont) consumer producer buffer(1) Put(4) class BoundedBuffer(maxSize: Int, putLatch: CountDownLatch, getLatch: CountDownLatch) extends Actor { var content = new Array[Int](size) var head, tail, curSize = 0 start override def act() = loop { react { case Put(x) if (curSize < maxSize) => { content(tail) = x tail = (tail + 1) % size curSize += 1 putLatch.countDown() } case Get if (curSize > 0) => { val r = content(head) head = (head + 1) % size curSize -= 1 reply(r) getLatch.countDown() Phase 2 4 Put(5) Get Phase 3 5 class BufferTest { @Test def testBuffer() { // … //Phase 2 producer ! Produce(List(4, 5)) putLatch.await() assert(consumer.token == 4 && buf.curSize == 1) // Phase 3 consumer ! Consume(1) getLatch.await() assert(consumer.token == 5 && buf.curSize == 0) } Setac Testing Framework 11/9/2018 Setac Testing Framework

Traditional BufferTest Problems Unreliable Thread.sleep Complexity and Deadlock possibility Latches and Barriers Costly Changing the program under test Setac Testing Framework 11/9/2018

Setac Testing Framework Specify tests with some constraints on the schedule Partial order of schedule messages Centralized schedule, less complexity Checking assertions when the system is stable There is no message that can be processed No progress in the system No change in the run time environment Minimal changes in the program under test Setac Testing Framework 11/9/2018

Setac Testing Framework Setac: BufferTest class BufferTest extends SetacTest { @Test def testBuffer() { val buf = new BoundedBuffer(1) val consumer = new Consumer(buf) val producer = new Producer(buf) val put4 = createScheduleMessage(producer, buf, Put(4)) val put5 = createScheduleMessage(producer, buf, Put(5)) val gets = createMultipleScheduleMessage(2, consumer, buf, Get) producer ! Produce(List(4, 5)) consumer ! Consume(2) //Phase 1 setSchedule(gets(0)) assertWhenStable(consumer.isBlocked && buf.curSize == 0) //Phase 2 setSchedule(put4 -> put5) assertWhenStable(consumer.token == 4 && buf.curSize == 1 && put5.isProcessed) // Phase 3 setSchedule(gets(1)) assertWhenStable(consumer.token == 5 && buf.curSize == 0) } Setac Testing Framework 11/9/2018

Setac: BufferTest (cont) class BoundedBuffer(size: Int) extends Actor { // … } class Consumer(buf: Actor) extends Actor { class Producer(buf: Actor) extends Actor { TestActor { TestActor { TestActor { Setac Testing Framework 11/9/2018 Setac Testing Framework

Setac Testing Framework Setac: BufferTest Removed Thread.sleep More reliable Removed synchronization constructs, e.g. Latches Reduced complexity Minimized changes in the program under test Setac Testing Framework 11/9/2018

Setac Testing Framework Setac APIs Follows widely used style for unit testing Integrated with Junit Refined over time based on examples Checking assertions when system is stable Total and partial order of schedule messages Status of Test messages Processed, delivered, etc. Status of actors Mail box: Number of messages, content of mail box, etc. Execution Status: Blocked, Running, Suspended Setac Testing Framework 11/9/2018

Setac Testing Framework Conclusions Large number of schedules in actor programs Only some schedules might be important to test It is non-trivial to force specific schedule and check assertions at appropriate times Sleeps - unreliable Latches – hard to write/read Changes in the program under test- high cost Setac Reliable Easy to write Very minimal changes in the program under test Open for collaboration Please try it: http://mir.cs.illinois.edu/setac/ Setac Testing Framework 11/9/2018

Setac Testing Framework Project Proposals Akka A better designed actor library for Scala users Supported by Typesafe and has been used for large real projects http://akka.io/docs/akka/1.1.3/additional/companies-using-akka.html Users always suffer from the lack of a testing framework Users don’t know how to test their actors Porting Setac for Akka A great contribution to Akka project Bigger user community Evaluating Setac Introducing a new approach/philosophy for testing actors Setac Testing Framework 11/9/2018

Setac Testing Framework Project Proposals Identifying the challenges and solutions for testing actor systems The most common bugs in actor systems (bug patterns) How to detect them and remove them How to prevent them from happening Facilitate Testing Trace simplification for debugging Record and replay traces Propose interesting schedules Setac Testing Framework 11/9/2018

Let’s Have a Big Contribution Setac Testing Framework 11/9/2018