Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Engineering and Architecture

Similar presentations


Presentation on theme: "Software Engineering and Architecture"— Presentation transcript:

1 Software Engineering and Architecture
Mandatory Project Distributed HotCiv

2 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, ... Henrik Bærbak Christensen

3 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... Henrik Bærbak Christensen

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

5 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: Henrik Bærbak Christensen

6 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 Henrik Bærbak Christensen

7 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!  Henrik Bærbak Christensen

8 Broker I Exercise

9 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 Henrik Bærbak Christensen

10 Limitations ... To lower your effort ...

11 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... Henrik Bærbak Christensen

12 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” 

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

14 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) Henrik Bærbak Christensen

15 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... Henrik Bærbak Christensen

16 So, first thing to do is... Make 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… Henrik Bærbak Christensen

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

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

19 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! Henrik Bærbak Christensen

20 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 Henrik Bærbak Christensen

21 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 ... Henrik Bærbak Christensen

22 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 Henrik Bærbak Christensen

23 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. Henrik Bærbak Christensen

24 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  Henrik Bærbak Christensen

25 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! Henrik Bærbak Christensen

26 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) Henrik Bærbak Christensen

27 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... Henrik Bærbak Christensen

28 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... Henrik Bærbak Christensen

29 Henrik Bærbak Christensen
Detailed Hints Henrik Bærbak Christensen

30 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... Henrik Bærbak Christensen

31 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... Henrik Bærbak Christensen

32 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. Henrik Bærbak Christensen

33 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... Henrik Bærbak Christensen

34 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 Henrik Bærbak Christensen

35 Broker 1.2

36 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... Henrik Bærbak Christensen

37 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? Henrik Bærbak Christensen

38 Henrik Bærbak Christensen
I did something like... Henrik Bærbak Christensen

39 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  Henrik Bærbak Christensen

40 Broker 1.3

41 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 Henrik Bærbak Christensen

42 Henrik Bærbak Christensen
Example Output Henrik Bærbak Christensen

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

44 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= Henrik Bærbak Christensen

45 Henrik Bærbak Christensen
Client Code Passing host parameter to the main method… Henrik Bærbak Christensen

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

47 Conclusion... Happy Coding!


Download ppt "Software Engineering and Architecture"

Similar presentations


Ads by Google