Software Engineering and Architecture

Slides:



Advertisements
Similar presentations
INFO 637Lecture #81 Software Engineering Process II Integration and System Testing INFO 637 Glenn Booker.
Advertisements

CSC 213 – Large Scale Programming. Why Do We Test?
Discussion of Assignment 9 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
The HotCiv GUI Instantiating the MiniDraw Framework.
CPSC 873 John D. McGregor Session 9 Testing Vocabulary.
Test Stubs... getting the world under control. TDD of State Pattern To implement GammaTown requirements I CS, AUHenrik Bærbak Christensen2.
Henrik Bærbak Christensen1 Test Driven Development “TDD” Summary.
HotCiv Project Starting up!. Henrik Bærbak Christensen2 HotCiv = Agile development Iterations of –product development –learning increments.
Multi Dimensional Variance: How to make ultra flexible software!
Mandatory 1 / AlphaCiv … Traps to be aware of …. Warn or not? I once asked Kent Beck the following –I have a lot of students in a course in design patterns.
Applying the Principles Two Examples. Example 1 New Requirement It would be nice with a simple GUI “to see something” instead of just xUnit tests...
Refactoring and Integration Testing or Strategy, introduced reliably by TDD The power of automated tests.
MiniDraw Introducing a Framework... and a few patterns.
Mandatory 1 / AlphaCiv … a few comments…. Overall: Generally – good work – good effort Seems you are generally doing TDD Minor hick-ups –”My own way is.
Mandatory 3 Test Stubs State Abstract Factory. Do not panic! dSoftArk is about Good analyzable design not about HotCiv! Henrik Bærbak Christensen2.
CPSC 372 John D. McGregor Module 8 Session 1 Testing.
Software Architecture in Practice A few notes on H1.
Function Parameters and Overloading Version 1.0. Topics Call-by-value Call-by-reference Call-by-address Constant parameters Function overloading Default.
Instantiating the MiniDraw Framework
INTRODUCTION TO ROBOTICS Part 5: Programming
Introducing a Framework ... and a few patterns
Summary prepared by Kirk Scott
Software Architecture in Practice
Debugging Intermittent Issues
John D. McGregor Session 9 Testing Vocabulary
Applying the Principles
What to do when a test fails
Input Space Partition Testing CS 4501 / 6501 Software Testing
Eclipse Navigation & Usage.
Exam A few notes and hints….
HotCiv Project Starting up!.
Mandatory 1 / AlphaCiv … Traps to be aware of ….
Debugging Intermittent Issues
COSC 220 Computer Science II
John D. McGregor Session 9 Testing Vocabulary
John D. McGregor Session 9 Testing Vocabulary
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Test-driven development (TDD)
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Reference This talk is loosely based on the following
Objects First with Java A Practical Introduction using BlueJ
Beginning Style 27-Feb-19.
CS 240 – Advanced Programming Concepts
CMPE212 – Reminders Assignment 3 due next Friday.
Objects First with Java A Practical Introduction using BlueJ
Extreme Programming.
Designing For Testability
CMPE212 – Reminders Assignment 2 due next Friday.
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Development Techniques
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Introduction to Methods and Interfaces
Presentation transcript:

Software Engineering and Architecture Mandatory Project Distributed HotCiv

Henrik Bærbak Christensen Some Experiences HotCiv is somewhat complex to ‘distribute’.. It was not designed with distribution in mind Which means the architecture is a bit mismatched It contains an Observer pattern Which our Broker does specifically not support ! There are a lot of methods Means a lot of ‘if (operationName.equals(xxx))’ It is multi-class and multi-object Game, City, Unit, Tile, It is a non-trivial code base Abstract Factory, Xstrategy, ... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Some Experiences So, I abandoned it the first year teaching SWEA Used another system (Breakthrough game), whose architecture matched distribution better But, Feedback indicated that students felt a bit disappointed not to push HotCiv all the way to the finishing line... had to understand a new system, no reuse of previous knowledge This year – we try to go the last mile... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Which Means... I have not been here before with students! Report issues !!! Perhaps a bit ”over hinted” this year... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Double Leap Making HotCiv distributed is not hard... ... Once you know all the details in Broker I solved the ‘hard parts’ in a couple of hours coding time Disclaimer – I probably know Broker pretty well by now after having written the book and fumbled my way through it for a couple of years in a couple of projects... ... But getting into the process of using Broker is hard! We will slit the work into two mandatory deliveries: CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Broker I Learning Goal Getting into the Broker pattern’s roles and implementation Develop all methods that are not returning object references to a large extend Reinforced learning of using test stubs to avoid big bang integration Product Goal JUnit Test suite, testing ClientProxy and Invoker code Integration testing, using socket based communication CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Broker II Learning Goal Get the return object reference methods implemented getUnitAt(p), and cousins... Get the SubInvokers integrated Get the MiniDraw GUI integrated in a full client Product Goal JUnit test suite that cover all broker related code System testing of a full HotCiv GUI based product! Wow!  CS@AU Henrik Bærbak Christensen

Broker I Exercise

Henrik Bærbak Christensen Exercises Broker 1.1 Develop much of Game’s methods Broker 1.2 Develop City, Unit, Tile methods Broker 1.3 Make a real manual integration test case using a real HotCivGameServer CS@AU Henrik Bærbak Christensen

Limitations ... To lower your effort ...

Henrik Bærbak Christensen You will only... ... Handle a single game on the server Only one GameServant object Thus its object id is irrelevant and no need to keep a datastructure of multiple servant objects ... Clients do not know who they are  Normally client 1 is RED while client 2 is BLUE RED client can try to move BLUE units when it is BLUE’s turn – but of course this is rejected You should disregard this aspect! That is, RED may move BLUE when BLUE’s turn Because we do then not need to distinguish between clients... CS@AU Henrik Bærbak Christensen

Or ”Do this or you may loose track of the path and despair”  Process Hints Or ”Do this or you may loose track of the path and despair” 

Henrik Bærbak Christensen Get the FRDS.Broker Just edit the build.gradle dependency section... 1.13 CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen What to implement? Broker roles Most are reused! Use the JSON marshalling (Gson) Use the Socket IPC Use Stubs/Your SemiCiv Missing are ClientProxies Invoker(s) CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Staring at the Screen How the h... do you start this exercise? I stared at the screen with a very blank expression for 10 minutes The starting point is to estalish the full broker chain of roles... CS@AU Henrik Bærbak Christensen

So, first thing to do is... Make the @Before method that set up the chain... Example: I simply write it, let IntelliJ create missing classes, all temporary test stub implementations Null observers? Will return shortly… CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Do it without IPC Take small steps and Keep Focus! TDD the Proxy+Invoker code first Go IPC/distribution next... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Use Stubs!!! Use a Game stub Create/reuse a Test Stub for the game CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Use Stubs!!! If you develop the Broker code using your full SemiCiv as Servant object... You likely run into big bang integration problems... You have a bug, debug for hours in your ClientProxy and Invoker, only to discover the bug is in the some weird strategy in the HotCiv code base  ”You want to move fast but have a 60kg backpack on your shoulders” Moving fast means no luggage! CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Example I have a StubGame3 implements Game as Servant , Servant { Why green city of size 4? Why is age 42? Why is winner YELLOW? Because a) it is easy to test against b) does not at all overlap at all with any known Civ behaviour so I know my client talk with the proper servant object CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Steal with Pride! It is a learning process, this one... Learn from TeleMed. (And GameLobby in Iteration 10) Have the code handy for reference ... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Go depth first... I advice to TDD the code depth-first Breath-first = make all ClientProxy methods first, next invoker Depth-first = make one ClientProxy method and drive all code into existence, that is the Invoker, until the test case pass That is, Step 1: Quickly add a Test CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Go depth first... Step 2: See test fails... Yeah!!! Step 3: Make a little change... Look at the TeleMed code and make the first method of the first abstraction in the call chain work – the GameProxy’s getWinner() method... Includes a lot of stuff like defining operation name string constants, etc etc. CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen objectId Issue Aahh, what about objectId??? Answer: Single game on server Exercise: What is the objectId Of course it is ”42” or ”myUniqueGameId” or ... Ignore it in the invoker as there is only one servant  CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Print Stuff! I print stuff to know ‘where am I’ and I can trace the call chain!!! Remove it again, once the test case pass! Or you when the output is no longer useful. Clean code! CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Step 2 or 4? Step 2: See it fail or Step 4: See it pass??? The printout tells me that I have Proxy at step 4: It works! The RequestObject looks OK Invoker at step 2: No code yet! That is – this test case drives TWO code pieces into existence, and the FIRST code piece is Step 4 (works) while the second is at Step 2 (Fail) and need the Step 3 (add a little code) CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Step 3, part 2 Step 3: Make a little change... Look at the TeleMed code and make the next method of the first abstraction in the call chain work – the GameInvoker’s handleRequest’s first switch on method name... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Step 4 A bit of Invoker coding later... Test pass Output looks OK – proper RequestObject and ReplyObject Conclusion One method of Game is now correctly work through the chain All required classes in place... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Detailed Hints CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Broker and Observer Our FRDS.Broker cannot handle Observer Pattern Server needs to call remote method on object that reside on the client side  And – there are two ???? Both Servant and ClientProxy has one, right? What to do? Disable them! Will return to them next week… Why: We do not need it at all, it is a pure client side GUI updating mechanism... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen If you are Lazy, like I The StubGame2 in the delivered MiniDraw code is lazy about the observer… So you get null ptr exceptions Rework StubGame, or nullObject the observers Why: We do not need it at all, it is a pure client side GUI updating mechanism... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Enums are Value types! Strings are classes in java and passed by reference! But they are really value types... So our Broker passes them as value types HotCiv also have value types Pass Player and Position as value types Teaser: What is ‘Tile’? Value? Reference? Tile is so simple it could be considered a Value type. I have made it into a reference type, just for consistency, but it is actually an overkill. CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen int, char, boolean, ... Java’s primitive types are primitive If you run into marshalling errors, then use the Java wrapper classes Integer.class Boolean.class Double Etc... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Remote or Not? Some methods in Game are not domain specific Exercise: If we ‘remote’ this method, what happens on Bente’s client when Arne invokes it? Morale: Do something intelligent CS@AU Henrik Bærbak Christensen

Broker 1.2

Henrik Bærbak Christensen City, Unit, Tile These interfaces’ methods all have value type return values So you can develop them! And you are asked to... The key obstacle, however, is the objectId... Which is the core learning goal of Broker Exercise II, next week For now Fake it till you make it... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Sidebar Exercise Why not pass them as value types? If we did, what issue would we run into? Because then ‘what the other player does of state changes to it’ will not be reflected in your client, rigth? CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen I did something like... CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Cost of the FakeIt code Next week, you will actually have to modify your (sub) Invokers quite a lot Take small steps, sometimes goes via code that needs to be removed again once we get to the final stages of the development. Scaffolding is not uncommon in other engineering disciplines  CS@AU Henrik Bærbak Christensen

Broker 1.3

Henrik Bærbak Christensen The Main Methods TDD and Stubs will get all the core code in place. Still, we need applications to run a distributed system HotCivServer’s main method HotCivClient’s main method You should develp the Server main method and a integration testing client ‘hotcivServer’ Start socket based server on localhost You choose  GameStub17 or SemiCiv ??? ‘hotcivStoryTest’ Run a user story as a single integration test Execute a few of the game’s methods CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Example Output CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen HotCivServer Add Gradle Task handling gradle hotcivServer And implement the server Again – steal with pride from the TeleMed code base! CS@AU Henrik Bærbak Christensen

hotcivStoryTest Add gradle task for that You need a ‘gradle.properties file to define the default host You can override the host setting using –Phost=(ip address) – IF you code the client to take parameters on from the argument list gradle hotcivManualClientTest –Phost=198.162.1.44 CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Client Code Passing host parameter to the main method… CS@AU Henrik Bærbak Christensen

Henrik Bærbak Christensen Manual Test method Let the client just exercise a scenario/some remote calls CS@AU Henrik Bærbak Christensen

Conclusion... Happy Coding!