Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

OSGi Versioning & Testing

4,932 views

Published on

Presentation given at Eclipse Summit Europe 2009.

OSGi Versioning & Testing

  1. 1. Chris Aniszczyk EclipseSource http://aniszczyk.org Paul VanderLei Band XI International
  2. 2. <ul><li>T elematics - O n- A - ST ick </li></ul><ul><li>Sample from upcoming book equinoxosgi.org </li></ul><ul><li>Example project in EclipseRT wiki.eclipse.org/Toast </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  3. 3. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Emergency Monitor Emergency Servlet GPS Channel Airbag Log
  4. 4. log get location OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Log Emergency Servlet Channel GPS Emergency Monitor Airbag
  5. 5. <ul><li>Versioning </li></ul><ul><li>Evolving API </li></ul><ul><li>Tools </li></ul><ul><li>Issues </li></ul><ul><li>Summary </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  6. 6. <ul><li>“ Software versioning is the process of assigning either unique version names or unique version numbers to unique states of computer software.” </li></ul><ul><li>Versioning is relative though… </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  7. 7. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  8. 8. <ul><li>Versioning is a marketing thing… </li></ul><ul><li>User’s don’t really care about versions… </li></ul><ul><li>Users just want to know if the version of the software they are running is current… </li></ul><ul><li>e.g., Ubuntu </li></ul><ul><ul><li>Feisty Fawn – 7.04 </li></ul></ul><ul><ul><li>Gutsy Gibbon – 7.10 </li></ul></ul><ul><ul><li>Hardy Heron – 8.04 </li></ul></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  9. 9. <ul><li>Version numbers are like dog tags * </li></ul><ul><li>Primarily used in an event of emergency… </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 * http://www.codinghorror.com/blog/archives/000793.html
  10. 10. <ul><li>Dependencies are defined on the module and package level </li></ul><ul><ul><li>Import-Package </li></ul></ul><ul><ul><li>Require-Bundle </li></ul></ul><ul><li>Ranges allow for flexibility </li></ul><ul><ul><li>Import-Package: org.easymock;version=[2.4.0,3.0.0) </li></ul></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  11. 11. <ul><li>major.minor.micro.qualifier </li></ul><ul><ul><li>major – An incompatible update; breaking API </li></ul></ul><ul><ul><li>minor – A backward compatible update; API stable </li></ul></ul><ul><ul><li>micro – A bug fix; no API changes </li></ul></ul><ul><ul><li>qualifier – build date; lexigraphic </li></ul></ul><ul><li>Versions should encode compatibility* at the bundle and package level </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 *http://wiki.eclipse.org/Version_Numbering
  12. 12. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Notice how the version numbers don’t necessarily match the 3.6 release?
  13. 13. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 <ul><li>Let’s evolve our GPS API… </li></ul>
  14. 14. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 <ul><li>Toast on a plane… we add height… </li></ul>
  15. 15. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 <ul><li>Management now wants an altimeter! </li></ul>
  16. 16. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 <ul><li>We broke API, need to fix versions! </li></ul>
  17. 17. <ul><li>Managing versions is important and painful </li></ul><ul><li>At Eclipse, we learned this lesson and have many experiences in dealing with maintaining and evolving API </li></ul><ul><li>Other projects eventually learn the importance of versioning… </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  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 &quot;unbreakable“ parts, and what is &quot;features of your own risk&quot; and so on.”
  19. 19. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 http://commons.apache.org/collections/compatibility.html “ 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.”
  20. 20. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  21. 21. <ul><li>Users need to understand the contract when using your software… </li></ul><ul><li>Good fences make for good neighbors! </li></ul><ul><li>Binary compatibility is important </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  22. 22. <ul><li>Binary compatibility is important </li></ul><ul><li>Maintaining binary compatibility is complex </li></ul><ul><li>Eclipse puts API on an altar… </li></ul><ul><li>Since Eclipse 3.4, Eclipse uses tools to manage and evolve API… </li></ul>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.html
  23. 23. <ul><li>Assists developers in API maintenance by reporting API defects such as binary incompatibilities, incorrect bundle version numbers and API usage. </li></ul><ul><li>Let’s revisit the GPS example… </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  24. 24. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  25. 25. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 <ul><li>Version number problems and quickfixes… </li></ul>
  26. 26. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 <ul><li>Let’s unknowingly break API… </li></ul>
  27. 27. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 <ul><li>Never break API again unless you want to! </li></ul>
  28. 28. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  29. 29. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 <ul><li>Understand API changes… </li></ul>
  30. 30. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  31. 31. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  32. 32. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  33. 33. <ul><li>Getting proper version ranges correct is difficult if there’s no consistent semantics </li></ul><ul><ul><li>e.g., log4j case… [1.2.0,1.3.0) or [1.2.0,2.0.0) ? </li></ul></ul><ul><li>Not all bundles are versioned properly in repositories </li></ul><ul><li>Tooling doesn’t cover packages yet… </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  34. 34. <ul><li>OSGi versions encode compatibility! </li></ul><ul><li>Don’t treat bundle versions like a marketing number </li></ul><ul><li>Scope your version ranges properly </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  35. 35. <ul><li>Good Practices </li></ul><ul><li>Sample Application </li></ul><ul><li>Unit Testing </li></ul><ul><li>System Testing </li></ul><ul><li>Remaining Issues </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  36. 36. <ul><li>Write your application as POJOs (plain-old-java-objects) </li></ul><ul><ul><li>No Service Trackers! </li></ul></ul><ul><ul><li>Whiteboard Pattern is tricky </li></ul></ul><ul><ul><li>Pay attention to dependencies </li></ul></ul><ul><ul><li>Unit testing depends on getting this right </li></ul></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  37. 37. <ul><li>Use Junit </li></ul><ul><li>Use mock objects (EasyMock, jMock...) </li></ul><ul><li>Minimize delays </li></ul><ul><li>No human interaction </li></ul><ul><li>Do TDD </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 “… I think that developers who can’t cope with any level of TDD shouldn’t be coding at all…”
  38. 38. <ul><li>Terminology </li></ul><ul><ul><li>Unit under test (UUT) </li></ul></ul><ul><ul><li>Test harness </li></ul></ul><ul><li>Test each POJO on its own (no OSGi) </li></ul><ul><li>Mock each dependency </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  39. 39. log get location OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 Log Emergency Servlet Channel GPS Emergency Monitor Airbag
  40. 40. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 get location Log Emergency Servlet GPS Channel Airbag Mock GPS Mock Channel Emergency Monitor Mock Airbag
  41. 41. <ul><li>Keep the test case in a separate project </li></ul><ul><ul><li>But POJO is not visible </li></ul></ul><ul><ul><li>Solution: </li></ul></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  42. 42. <ul><li>Dependencies </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  43. 43. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  44. 44. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  45. 45. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  46. 46. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  47. 47. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  48. 48. <ul><li>Test as much of system as possible </li></ul><ul><li>OSGi is present </li></ul><ul><li>Test full system flow </li></ul><ul><li>Test bundles coming and going </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  49. 49. log get location OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0 deploy Log Mock Log Emergency Servlet Channel GPS Emergency Monitor Airbag Mock Airbag Test Case
  50. 50. <ul><li>Normal Plug-in Project </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  51. 51. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  52. 52. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  53. 53. <ul><li>PDE Junit test infrastructure </li></ul><ul><ul><li>uses Equinox extensions </li></ul></ul><ul><li>Declarative Services </li></ul><ul><ul><li>uses OSGi services </li></ul></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  54. 54. <ul><li>Junit instantiates the test case as usual </li></ul><ul><ul><li>setup() </li></ul></ul><ul><ul><li>testEmergency() </li></ul></ul><ul><li>Problem: no way to obtain: </li></ul><ul><ul><li>bundle context </li></ul></ul><ul><ul><li>mock airbag </li></ul></ul><ul><ul><li>mock log </li></ul></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  55. 55. <ul><li>Instantiates the test case as a component </li></ul><ul><li>DS dependency injection </li></ul><ul><ul><li>setAirbag(<our mock airbag>) </li></ul></ul><ul><ul><li>setLog(<our mock log>) </li></ul></ul><ul><ul><li>startup() </li></ul></ul><ul><li>Problem: </li></ul><ul><ul><li>This instance is never used by Junit! </li></ul></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  56. 56. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  57. 57. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  58. 58. OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  59. 59. <ul><li>Still very tricky </li></ul><ul><li>Not well-supported by PDE tooling </li></ul><ul><li>Validation by logging is fragile </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0
  60. 60. <ul><li>Get the slides: tinyurl.com/osgiVT </li></ul><ul><li>Get the code: wiki.eclipse.org/Toast </li></ul><ul><li>Get the book: equinoxosgi.org </li></ul>OSGi Versioning and Testing | © Copyright 2009 EclipseSource & Band XI International; made available under EPL v1.0

×