Play! Framework – Поиграем? – Why Play!?



Play! Framework – Поиграем? – Why Play!?

0 0


devclub-presentation

08.2012 Devclub Play! framework presentation

On Github vadger / devclub-presentation

Play! Framework

Поиграем?

Vadim Gerassimov Codeborne OÜ

Brief overview

MVC action based framework

Stateless

Runtime class reloading

Convention over configuration

Built-in HTTP server

No Servlet API

Inspired by Rails

Why Play!?

Situation we had

Considered frameworks

Situation we had

We had only 2 weeks to make quite functional prototype

We had no constraints in technology selection

We wanted something lightweight and new

We wanted to be efficient

Considered frameworks (1)

Well known (already boring) frameworks:

  • Struts 2
  • Spring MVC

Considered frameworks (2)

Something new and fun:

  • Play!
  • Play! + Scala
  • Play 2

Play! for prototyping

Small learning curve to start fast

No redeploy needed to code fast

JPA 2 out of the box for fast models creation/modification

H2 in-memory database for speed and simplicity

It's demo time!

Play! for real project

Bank na Play eto nomer konechno :-) Slava Rosin via g+

Dependency injection

Play! has no DI out of the box

Play! approach: controller + model that also acts as DAO

Does not work good if you have several backends

Play! has Guice integration via modules (Spring too)

Caching

Due to slow backend caching was a must

Hopefully, Play! has cache support out of the box

EhCache for single instance applications we used initially

Memcached for multiple instances we were forced to switch after

With Guice method interceptors we made caching more elegant

  
      @Singleton
      public class ABCDCoreService implements CoreService {
      @Cached(name = "customer", expires="5mn") @Override
      public Customer customer(long id) {
      ....
      }
      }
  

Jobs

Play! has out of the box jobs support

On application start/stop jobs

Scheduled jobs: simple @Every("5mn") or more complex cron like @On("0 0 12 * * ?")

Or even run job from controller

By default jobs run in transaction

Also you can manage transactions manually

DB evolutions

Tracking database schema changes is essential

Play! has built in support for managing DB evolutions

  
      # -- 1.sql
      # --- !Ups
      ALTER TABLE User ADD age INT;

      # --- !Downs
      ALTER TABLE User DROP age;
  

In dev mode changes are detected on request

In prod mode: play evolutions:apply

In v.1.2.4 evolutions didn't work out of the box with Oracle :)

Build and release

No Ant/Maven

No WAR (however, Play! has WAR support)

Just hardcore custom .sh build script

Separate script for fast test env update

Jenkins for Continuous Integration

Unit and UI tests run separately due to conflicts

Testing

Play! has 3 level of testing:

  • Unit testing for isolated testing
  • Functional testing for whole app testing except UI
  • UI testing for testing user interaction

But Play! standard solution didn't suit us

  • Functional tests don't cover UI
  • Writing Selenium tests is far from ideal

Our approach:

  • JUnit + Mockito + PowerMockito for Unit tests
  • JUnit + WebDriver + Selenide for UI tests

https://github.com/codeborne/play-selenide

It's demo time!

THE END

Questions?

Presentation available at:

http://vadger.github.com/devclub-presentation/index.html