Click here to load reader

Chris Aniszczyk EclipseSource aniszczyk.org Paul VanderLei Band XI International tinyurl.com/paul-vanderlei

  • View
    217

  • Download
    1

Embed Size (px)

Text of Chris Aniszczyk EclipseSource aniszczyk.org Paul VanderLei Band XI International...

  • Slide 1

Chris Aniszczyk EclipseSource aniszczyk.org Paul VanderLei Band XI International tinyurl.com/paul-vanderlei Slide 2 T elematics -On-A-STick Sample from upcoming book equinoxosgi.org equinoxosgi.org Example project in EclipseRT wiki.eclipse.org/Toast wiki.eclipse.org/Toast 2 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 3 3 Emergency Monitor Emergency Servlet GPS Channel Airbag Log Slide 4 log Emergency Servlet HTTP Channel send GPS get location Emergency Monitor notify 4 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Airbag Slide 5 Versioning Evolving API Tools Issues Summary 5 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 6 Software versioning is the process of assigning either unique version names or unique version numbers to unique states of computer software. Versioning is relative though 6 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 7 State of versioning is a bit ridiculous Java 1.0.3, 1.1.2, 1.4.2, 1.5.0, 1.6.0 (why leave the 1.?) Windows 3.1, 2000, XP, ME, 7 (wtf?) Netscape 4, 5, 6 (skipping versions due to IE6 competition) Linux 2.3, 2.4.0, 2.6.8, 2.6.8.1 (odd dev, even stable) SmallEiffel -0.87 -0.79 -0.74 counting down to 0 7 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 8 8 Versioning is a marketing thing Users dont really care about versions Users just want to know if the version of the software they are running is current e.g., Ubuntu Feisty Fawn 7.04 Gutsy Gibbon 7.10 Hardy Heron 8.04 Slide 9 9 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Version numbers are like dog tags* Primarily used in an event of emergency *http://www.codinghorror.com/blog/archives/000793.htm l Slide 10 Dependencies are defined on the module and package level Import-Package Require-Bundle Ranges allow for flexibility Import-Package: org.easymock;version=[2.4.0,3.0.0) 10 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 11 major.minor.micro.qualifier major An incompatible update; breaking API minor A backward compatible update; API stable micro A bug fix; no API changes qualifier build date; lexigraphic Versions should encode compatibility* at the bundle and package level 11 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 *http://wiki.eclipse.org/Version_Numbering Slide 12 12 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Notice how the version numbers dont necessarily match the 3.6 release? Slide 13 13 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 GPS 1.0.0 getHeading() getLatitude() getLongitude() getSpeed() Lets evolve our GPS API Slide 14 GPS 1.1.0 getHeading() getLatitude() getLongitude() getSpeed() getHeight() 14 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Toast on a plane we add height Slide 15 GPS 1.2.0 getHeading() getLatitude() getLongitude() getSpeed() getHeight() 15 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Altimeter 1.0.0 getHeight() Management now wants an altimeter! Slide 16 GPS 2.0.0 getHeading() getLatitude() getLongitude() getSpeed() 16 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Altimeter 1.0.0 getHeight() We broke API, need to fix versions! Slide 17 Managing versions is important and painful At Eclipse, we learned this lesson and have many experiences in dealing with maintaining and evolving API Other projects eventually learn the importance of versioning 17 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 18 18 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 I still believe a an official compatibility statement are in order. It includes a definition of the API and a separate definition of the SPI, and possible a third definition of the Configuration. I bet everyone would back such statement, would clarify the "unbreakable parts, and what is "features of your own risk" and so on. Slide 19 19 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Commons collections 3.0 is binary compatible with version 2.1 and 2.0 except for certain methods on one class. As the release was a major version, this is permitted, however it was unintentional and an error the chosen solution is to provide a work around by releasing v2.1.1 and v3.1. http://commons.apache.org/collections/compatibility.html Slide 20 20 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 21 Users need to understand the contract when using your software Good fences make for good neighbors! Binary compatibility is important 21 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 22 Binary compatibility is important Maintaining binary compatibility is complex Eclipse puts API on an altar Since Eclipse 3.4, Eclipse uses tools to manage and evolve API 22 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 *http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.ht ml Slide 23 Assists developers in API maintenance by reporting API defects such as binary incompatibilities, incorrect bundle version numbers and API usage. Lets revisit the GPS example 23 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 24 24 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 We need height! Slide 25 25 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Version number problems and quickfixes Slide 26 26 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Lets unknowingly break API Slide 27 27 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Never break API again unless you want to! Slide 28 28 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 29 29 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Understand API changes Slide 30 30 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Understand who uses your API given a set of bundles Slide 31 31 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 22 GPS API References Slide 32 32 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 API Reference Details Slide 33 Getting proper version ranges correct is difficult if theres no consistent semantics e.g., log4j case [1.2.0,1.3.0) or [1.2.0,2.0.0) ? Not all bundles are versioned properly in repositories Tooling doesnt cover packages yet 33 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 34 OSGi versions encode compatibility! Dont treat bundle versions like a marketing number Scope your version ranges properly 34 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 35 Good Practices Sample Application Unit Testing System Testing Remaining Issues 35 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 36 Write your application as POJOs (plain-old-java-objects) No Service Trackers! Whiteboard Pattern is tricky Pay attention to dependencies Unit testing depends on getting this right 36 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 37 Use Junit Use mock objects (EasyMock, jMock...) Minimize delays No human interaction Do TDD 37 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 I think that developers who cant cope with any level of TDD shouldnt be coding at all Slide 38 Terminology Unit under test (UUT) Test harness Test each POJO on its own (no OSGi) Mock each dependency 38 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 39 Log log Emergency Servlet HTTP Channel send GPS get location Emergency Monitor notify 39 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Airbag Slide 40 Log test harness UUT 40 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Emergency Servlet GPS Channel Airbag Mock GPS Mock Channel send get location Emergency Monitor notify Mock Airbag Slide 41 Keep the test case in a separate project But POJO is not visible Solution: 41 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 42 42 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Dependencies Junit & EasyMock dependency interfaces Slide 43 43 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 create UUT create mock GPS Slide 44 44 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 create mock airbag Slide 45 45 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 create mock channel Slide 46 46 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 run the test Slide 47 47 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 48 Test as much of system as possible OSGi is present Test full system flow Test bundles coming and going 48 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 49 Log Mock Log test harness UUT log Emergency Servlet HTTP Channel send GPS get location Emergency Monitor notify 49 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Airbag Mock Airbag deploy verify Test Case Slide 50 50 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Normal Plug-in Project declares 3 components Slide 51 51 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 hook for testing Slide 52 52 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 hook for testing Slide 53 PDE Junit test infrastructure uses Equinox extensions Declarative Services uses OSGi services 53 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 54 Junit instantiates the test case as usual setup() testEmergency() Problem: no way to obtain: bundle context mock airbag mock log 54 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 55 Instantiates the test case as a component DS dependency injection setAirbag( ) setLog( ) startup() Problem: This instance is never used by Junit! 55 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 56 56 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 DS invokes these instances share these ready to run test case Slide 57 57 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 stop GPS bundle normal test wait until DS has activated start GPS bundle Slide 58 58 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 59 Still very tricky Not well-supported by PDE tooling Validation by logging is fragile 59 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Slide 60 Get the slides: tinyurl.com/osgiVTtinyurl.com/osgiVT Get the code: wiki.eclipse.org/Toastwiki.eclipse.org/Toast Get the book: equinoxosgi.orgequinoxosgi.org 60 OSGi Versioning and Testing | Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0