SlideShare a Scribd company logo
1 of 69
Download to read offline
Saturday, June 16, 12
Saturday, June 16, 12
Acerca de


                        •   Programador en Liip AG | Zürich

                        •   Blog: http://videlalvaro.github.com/

                        •   Twitter: @old_sound




Saturday, June 16, 12
Hecho en Uruguay




Saturday, June 16, 12
Acerca de
                        Co Autor de

                 ConillMQ en acció
               http://bit.ly/rabbitmq




Saturday, June 16, 12
Acerca de
                        Co Autor de

                RabbitMQ in Action
               http://bit.ly/rabbitmq




Saturday, June 16, 12
No Soy




Saturday, June 16, 12
No Soy

                        • Gurú del testeo de aplicaciones




Saturday, June 16, 12
No Soy

                        • Guru del testeo de aplicaciones
                        • Abogado del TDD




Saturday, June 16, 12
Unit Testing

                 The goal of unit testing is to isolate
                 each part of the program and show
                    that the individual parts are
                               correct.

                             http://en.wikipedia.org/wiki/Unit_testing




Saturday, June 16, 12
Unit Tests

                          Por definición, sólo prueban las unidades
                          por sí solas. Por lo tanto, no descubrirán
                            errores de integración, problemas de
                        rendimiento y otros problemas que afectan a
                               todo el sistema en su conjunto.


                                    http://es.wikipedia.org/wiki/Prueba_unitaria




Saturday, June 16, 12
Dogma
                          vs.
                        Realidad


Saturday, June 16, 12
Trade Offs



Saturday, June 16, 12
¿Qué testear?



Saturday, June 16, 12
¿Cuánto testear?



Saturday, June 16, 12
"I get paid for code that works, not
          for tests, so my philosophy is to test
           as little as possible to reach a given
                     level of confidence"
                                      – Kent Beck

                        http://stackoverflow.com/questions/153234/how-deep-are-your-unit-tests/153565#153565




Saturday, June 16, 12
El Secreto del TDD



Saturday, June 16, 12
El Secreto del TDD




Saturday, June 16, 12
El Secreto del TDD




Saturday, June 16, 12
Algunos Libros de Kent Beck




Saturday, June 16, 12
Para escribir buenos
                        Tests primero hay que
                           saber programar


Saturday, June 16, 12
Saturday, June 16, 12
Los
                   Programadores
                  somos como los
                 usuarios de los que
                      tanto nos
                      quejamos
Saturday, June 16, 12
El diseño se madura y
                        macera con el tiempo


Saturday, June 16, 12
TIPS



Saturday, June 16, 12
Separar el código puro
                         del impuro o stateful


Saturday, June 16, 12
Funciones Puras




Saturday, June 16, 12
Funciones Puras
                        • Devuelven datos en bases a los parámetros
                          que aceptan




Saturday, June 16, 12
Funciones Puras
                        • Devuelven datos en bases a los parámetros
                          que aceptan
                        • No modifican estado externo




Saturday, June 16, 12
Funciones Puras
                        • Devuelven datos en bases a los parámetros
                          que aceptan
                        • No modifican estado externo
                        • No producen efectos secundarios



Saturday, June 16, 12
¿Qué tiene de malo este código?

                        if($player->getScore() > 0) {
                          $player->setSwizzle(7);
                        } else {
                          $player->setSwizzle(
                             $player->getSwizzle() + 1
                          );
                        }



                          http://dl.dropbox.com/u/7810909/docs/what-does-fp-mean/what-does-fp-mean/chunk-html/ar01s05.html




Saturday, June 16, 12
Version que no mezcla modificaciones de estado


              $newScore = $player->getScore() > 0
                        ? 7
                        : $player->getSwizzle() + 1;

              $player->setSwizzle($newScore);




                        http://dl.dropbox.com/u/7810909/docs/what-does-fp-mean/what-does-fp-mean/chunk-html/ar01s05.html




Saturday, June 16, 12
El cálculo del Score se
                         puede extraer a una
                                función


Saturday, June 16, 12
El cálculo del Score se
                             puede testear


Saturday, June 16, 12
Primero Escribir
                          Código Puro


Saturday, June 16, 12
Agregar paso a
                          paso el codigo
                        impuro necesario


Saturday, June 16, 12
Código Fácil de
                         Componer


Saturday, June 16, 12
Function Composition




                             http://en.wikipedia.org/wiki/Function_(mathematics)




Saturday, June 16, 12
Function Composition




                             http://en.wikipedia.org/wiki/Function_(mathematics)




Saturday, June 16, 12
Esto suena familiar



Saturday, June 16, 12
“Many UNIX programs do
             quite trivial tasks in
           isolation, but, combined
             with other programs,
          become general and useful
                    tools.”
                        http://math.albany.edu/math/pers/hammond/unixphil.html




Saturday, June 16, 12
Number of open connections per IP



             netstat -ntu | awk '{print $5}' | 
             cut -d: -f1 | sort | uniq -c | sort -n




                          http://www.commandlinefu.com/commands/view/1767/number-of-open-connections-per-ip.




Saturday, June 16, 12
¿Por qué no programar
                    código de esa forma?


Saturday, June 16, 12
Esto suena familiar



Saturday, June 16, 12
¡Bienvenido a la
                         Programación
                           Funcional!

Saturday, June 16, 12
“Writing unit tests is
                            reinventing
                              functional
                           programming
                         in non-functional
                             languages”
                        http://noss.github.com/2009/02/25/writing-unit-tests-is-reinventing-functional-programming-in-non-functional-languages.html




Saturday, June 16, 12
¿Qué nos enseña la
                          programación
                            funcional?


Saturday, June 16, 12
Uso Correcto de Types



Saturday, June 16, 12
¿Qué significa ‘null’?



Saturday, June 16, 12
¿Qué significa
                        ‘false|true’?


Saturday, June 16, 12
Código
                        semánticamente
                           correcto

Saturday, June 16, 12
Vamos a hacer la
                           comida


Saturday, June 16, 12
Vamos a cocinar la
                            comida


Saturday, June 16, 12
Funciones que cumplen
                     sólo una función


Saturday, June 16, 12
Separación radical
                            de código
                        puro del impuro


Saturday, June 16, 12
Veamos un Ejemplo
                           http://pastie.org/4097327



Saturday, June 16, 12
Testeando AMQP



                        https://github.com/videlalvaro/php-amqplib/


Saturday, June 16, 12
Testeando queue_declare

        public	
  function	
  queue_declare($queue="",	
  $passive=false,	
  $durable=false,	
  	
  	
  
                                                    	
  $exclusive=false,	
  $auto_delete=true,	
  $nowait=false,	
  
                                                    	
  $arguments=NULL,	
  $ticket=NULL)
        {
        	
  	
  if($arguments	
  ==	
  NULL)
        	
  	
  	
  	
  $arguments	
  =	
  array();

        	
  	
  	
  $args	
  =	
  new	
  AMQPWriter();
        	
  	
  	
  if($ticket	
  !=	
  NULL)
        	
  	
  	
  	
  	
  $args-­‐>write_short($ticket);
        	
  	
  	
  else
        	
  	
  	
  	
  	
  $args-­‐>write_short($this-­‐>default_ticket);
        	
  	
  	
  $args-­‐>write_shortstr($queue);
        	
  	
  	
  $args-­‐>write_bit($passive);
        	
  	
  	
  $args-­‐>write_bit($durable);
        	
  	
  	
  $args-­‐>write_bit($exclusive);
        	
  	
  	
  $args-­‐>write_bit($auto_delete);
        	
  	
  	
  $args-­‐>write_bit($nowait);
        	
  	
  	
  $args-­‐>write_table($arguments);
        	
  	
  	
  $this-­‐>send_method_frame(array(50,	
  10),	
  $args);

        	
  	
  	
  if(!$nowait)
        	
  	
  	
  	
  	
  return	
  $this-­‐>wait(array("50,11"));	
  	
  	
  	
  //	
  Channel.queue_declare_ok
        }




Saturday, June 16, 12
Testeando queue_declare
           class	
  AMQPChannel	
  extends	
  AbstractChannel
           {
           	
  	
  public	
  function	
  __construct($connection,	
  $channel_id=null,	
  $auto_decode=true)
           	
  	
  {
           	
  	
  	
  	
  $this-­‐>frameBuilder	
  =	
  new	
  FrameBuilder();

           	
  	
  	
  	
  if	
  ($channel_id	
  ==	
  null)	
  {
           	
  	
  	
  	
  	
  	
  $channel_id	
  =	
  $connection-­‐>get_free_channel_id();
           	
  	
  	
  	
  }

           	
  	
  	
  	
  parent::__construct($connection,	
  $channel_id);

           	
  	
  	
  	
  if	
  ($this-­‐>debug)	
  {
           	
  	
  	
  	
  	
  	
  MiscHelper::debug_msg("using	
  channel_id:	
  "	
  .	
  $channel_id);
           	
  	
  	
  	
  }

           	
  	
  	
  	
  $this-­‐>default_ticket	
  =	
  0;
           	
  	
  	
  	
  $this-­‐>is_open	
  =	
  false;
           	
  	
  	
  	
  $this-­‐>active	
  =	
  true;	
  //	
  Flow	
  control
           	
  	
  	
  	
  $this-­‐>alerts	
  =	
  array();
           	
  	
  	
  	
  $this-­‐>callbacks	
  =	
  array();
           	
  	
  	
  	
  $this-­‐>auto_decode	
  =	
  $auto_decode;

           	
  	
  	
  	
  $this-­‐>x_open();
           	
  	
  }
           	
  	
  /*	
  ...	
  más	
  métodos	
  y	
  propiedades	
  omitidos	
  */
           }



Saturday, June 16, 12
Testeando queue_declare



                        public	
  function	
  queueDeclare($queue,	
  $passive,	
  $durable,	
  $exclusive,	
  
                                                                            $auto_delete,	
  $nowait,	
  $arguments,	
  $ticket)
                        {
                        	
  	
  $args	
  =	
  new	
  AMQPWriter();
                        	
  	
  $args-­‐>write_short($ticket)
                        	
  	
  	
  	
  	
  	
  	
  -­‐>write_shortstr($queue)
                        	
  	
  	
  	
  	
  	
  	
  -­‐>write_bit($passive)
                        	
  	
  	
  	
  	
  	
  	
  -­‐>write_bit($durable)
                        	
  	
  	
  	
  	
  	
  	
  -­‐>write_bit($exclusive)
                        	
  	
  	
  	
  	
  	
  	
  -­‐>write_bit($auto_delete)
                        	
  	
  	
  	
  	
  	
  	
  -­‐>write_bit($nowait)
                        	
  	
  	
  	
  	
  	
  	
  -­‐>write_table($arguments);
                        	
  	
  return	
  $args;
                        }




Saturday, June 16, 12
Testeando queue_declare


                public	
  function	
  queue_declare($queue="",	
  $passive=false,	
  $durable=false,	
  	
  	
  
                	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  $exclusive=false,	
  $auto_delete=true,	
  $nowait=false,	
  
                	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  $arguments=NULL,	
  $ticket=NULL)
                {
                	
  	
  $arguments	
  =	
  $this-­‐>getArguments($arguments);
                	
  	
  $ticket	
  =	
  $this-­‐>getTicket($ticket);

                	
  	
  $args	
  =	
  $this-­‐>frameBuilder-­‐>queueDeclare(
                	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  $queue,	
  $passive,	
  $durable,	
  $exclusive,
                                                                                                       	
  $auto_delete,	
  $nowait,	
  $arguments,	
  $ticket);
                	
  	
  
                	
  	
  $this-­‐>send_method_frame(array(50,	
  10),	
  $args);

                	
  	
  if	
  (!$nowait)	
  {
                	
  	
  	
  	
  return	
  $this-­‐>wait(array("50,11"));	
  	
  	
  	
  //	
  Channel.queue_declare_ok	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
                	
  	
  }
                }




Saturday, June 16, 12
Testeando queue_declare



                        public	
  function	
  testQueueDeclare()
                        {
                        	
  	
  $expected	
  =	
  "x00x00x03foox00x00x00x00x00";
                        	
  	
  $args	
  =	
  $this-­‐>frameBuilder
                        	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  -­‐>queueDeclare(
                                                                                         	
  	
  	
  'foo',	
  false,	
  false,	
  false,	
  false,	
  false,	
  array(),	
  0
                                                                                         );
                        	
  	
  $this-­‐>assertEquals($expected,	
  $args-­‐>getvalue());
                        }




Saturday, June 16, 12
¿Cómo aplico esto al
                           mundo real?




Saturday, June 16, 12
¿Cómo aplico esto al
                            mundo real?

                        • Ver la charla de Ricard “Servicios en
                          Symfony2”




Saturday, June 16, 12
¿Cómo aplico esto al
                            mundo real?

                        • Ver la charla de Ricard “Servicios en
                          Symfony2”
                        • Muchos servicios especializados y
                          desacoplados




Saturday, June 16, 12
¿Cómo aplico esto al
                            mundo real?

                        • Ver la charla de Ricard “Servicios en
                          Symfony2”
                        • Muchos servicios especializados y
                          desacoplados
                        • Clases que cumplen sólo una función

Saturday, June 16, 12
“Inside every well-
                           written large
                              program
                         is a well-written
                          small program”
                              http://www.linfo.org/q_programming.html




Saturday, June 16, 12
¿Preguntas?



Saturday, June 16, 12
¡Gracias!
                                 Álvaro Videla
                           http://twitter.com/old_sound
                           http://github.com/videlalvaro
                        http://www.slideshare.net/old_sound




Saturday, June 16, 12

More Related Content

Viewers also liked

Writing testable code
Writing testable codeWriting testable code
Writing testable codeAlvaro Videla
 
Interoperability With RabbitMq
Interoperability With RabbitMqInteroperability With RabbitMq
Interoperability With RabbitMqAlvaro Videla
 
Integrating RabbitMQ with PHP
Integrating RabbitMQ with PHPIntegrating RabbitMQ with PHP
Integrating RabbitMQ with PHPAlvaro Videla
 
A realtime infrastructure for Android apps: Firebase may be what you need..an...
A realtime infrastructure for Android apps: Firebase may be what you need..an...A realtime infrastructure for Android apps: Firebase may be what you need..an...
A realtime infrastructure for Android apps: Firebase may be what you need..an...Alessandro Martellucci
 
Tdd in android (mvp)
Tdd in android (mvp)Tdd in android (mvp)
Tdd in android (mvp)Prateek Jain
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter rendra toro
 
Android Architecture MVP Pattern
Android Architecture MVP Pattern Android Architecture MVP Pattern
Android Architecture MVP Pattern Jeff Potter
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014Thomas Lockney
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & designallegro.tech
 
Infinum Android Talks #12 - MVP design pattern for Android Apps
Infinum Android Talks #12 - MVP design pattern for Android AppsInfinum Android Talks #12 - MVP design pattern for Android Apps
Infinum Android Talks #12 - MVP design pattern for Android AppsInfinum
 
Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Ken William
 
Android cleanarchitecture
Android cleanarchitectureAndroid cleanarchitecture
Android cleanarchitectureTomoaki Imai
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaKasun Indrasiri
 

Viewers also liked (19)

Messaging patterns
Messaging patternsMessaging patterns
Messaging patterns
 
Writing testable code
Writing testable codeWriting testable code
Writing testable code
 
Android MVVM TDD
Android MVVM TDDAndroid MVVM TDD
Android MVVM TDD
 
Interoperability With RabbitMq
Interoperability With RabbitMqInteroperability With RabbitMq
Interoperability With RabbitMq
 
Integrating RabbitMQ with PHP
Integrating RabbitMQ with PHPIntegrating RabbitMQ with PHP
Integrating RabbitMQ with PHP
 
A realtime infrastructure for Android apps: Firebase may be what you need..an...
A realtime infrastructure for Android apps: Firebase may be what you need..an...A realtime infrastructure for Android apps: Firebase may be what you need..an...
A realtime infrastructure for Android apps: Firebase may be what you need..an...
 
Tdd in android (mvp)
Tdd in android (mvp)Tdd in android (mvp)
Tdd in android (mvp)
 
Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)Reactive Java (GeeCON 2014)
Reactive Java (GeeCON 2014)
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter
 
Android Architecture MVP Pattern
Android Architecture MVP Pattern Android Architecture MVP Pattern
Android Architecture MVP Pattern
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
 
Building maintainable app
Building maintainable appBuilding maintainable app
Building maintainable app
 
Introduction to Reactive Java
Introduction to Reactive JavaIntroduction to Reactive Java
Introduction to Reactive Java
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & design
 
Infinum Android Talks #12 - MVP design pattern for Android Apps
Infinum Android Talks #12 - MVP design pattern for Android AppsInfinum Android Talks #12 - MVP design pattern for Android Apps
Infinum Android Talks #12 - MVP design pattern for Android Apps
 
Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~
 
Android cleanarchitecture
Android cleanarchitectureAndroid cleanarchitecture
Android cleanarchitecture
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
 
Effective Android UI - English
Effective Android UI - EnglishEffective Android UI - English
Effective Android UI - English
 

Similar to Código Fácil De Testear

deSymfony 2012 - El entorno de Symfony2
deSymfony 2012 - El entorno de Symfony2deSymfony 2012 - El entorno de Symfony2
deSymfony 2012 - El entorno de Symfony2Albert Jessurum
 
Android meetup
Android meetupAndroid meetup
Android meetupTy Smith
 
Real Developer Tools for WordPress by Stefan Didak
Real Developer Tools for WordPress by Stefan DidakReal Developer Tools for WordPress by Stefan Didak
Real Developer Tools for WordPress by Stefan DidakEast Bay WordPress Meetup
 
Continuous delivery agile_2012
Continuous delivery agile_2012Continuous delivery agile_2012
Continuous delivery agile_2012drewz lin
 
Ux paper prototyping
Ux paper prototypingUx paper prototyping
Ux paper prototypingGrace Ng
 
Responsive Process - London 2012
Responsive Process - London 2012Responsive Process - London 2012
Responsive Process - London 2012Steve Fisher
 
What do you mean, backwards compatibility?
What do you mean, backwards compatibility?What do you mean, backwards compatibility?
What do you mean, backwards compatibility?Trisha Gee
 
5 Ways to Awesome-ize Your (PHP) Code
5 Ways to Awesome-ize Your (PHP) Code5 Ways to Awesome-ize Your (PHP) Code
5 Ways to Awesome-ize Your (PHP) CodeJeremy Kendall
 
Scaling Django to the sky
Scaling Django to the skyScaling Django to the sky
Scaling Django to the skyNaren Arya
 
Disposable Testing Environments: There's Nothing Like Production Except Produ...
Disposable Testing Environments: There's Nothing Like Production Except Produ...Disposable Testing Environments: There's Nothing Like Production Except Produ...
Disposable Testing Environments: There's Nothing Like Production Except Produ...Atlassian
 
Show an Open Source Project Some Love and Start Using Travis-CI
Show an Open Source Project Some Love and Start Using Travis-CIShow an Open Source Project Some Love and Start Using Travis-CI
Show an Open Source Project Some Love and Start Using Travis-CIJoel Byler
 

Similar to Código Fácil De Testear (14)

deSymfony 2012 - El entorno de Symfony2
deSymfony 2012 - El entorno de Symfony2deSymfony 2012 - El entorno de Symfony2
deSymfony 2012 - El entorno de Symfony2
 
JavaScript QA Tools
JavaScript QA ToolsJavaScript QA Tools
JavaScript QA Tools
 
Android meetup
Android meetupAndroid meetup
Android meetup
 
Real Developer Tools for WordPress by Stefan Didak
Real Developer Tools for WordPress by Stefan DidakReal Developer Tools for WordPress by Stefan Didak
Real Developer Tools for WordPress by Stefan Didak
 
Continuous delivery agile_2012
Continuous delivery agile_2012Continuous delivery agile_2012
Continuous delivery agile_2012
 
Ux paper prototyping
Ux paper prototypingUx paper prototyping
Ux paper prototyping
 
Responsive Process - London 2012
Responsive Process - London 2012Responsive Process - London 2012
Responsive Process - London 2012
 
What do you mean, backwards compatibility?
What do you mean, backwards compatibility?What do you mean, backwards compatibility?
What do you mean, backwards compatibility?
 
5 Ways to Awesome-ize Your (PHP) Code
5 Ways to Awesome-ize Your (PHP) Code5 Ways to Awesome-ize Your (PHP) Code
5 Ways to Awesome-ize Your (PHP) Code
 
DevOps and Chef
DevOps and ChefDevOps and Chef
DevOps and Chef
 
The Testable Web
The Testable WebThe Testable Web
The Testable Web
 
Scaling Django to the sky
Scaling Django to the skyScaling Django to the sky
Scaling Django to the sky
 
Disposable Testing Environments: There's Nothing Like Production Except Produ...
Disposable Testing Environments: There's Nothing Like Production Except Produ...Disposable Testing Environments: There's Nothing Like Production Except Produ...
Disposable Testing Environments: There's Nothing Like Production Except Produ...
 
Show an Open Source Project Some Love and Start Using Travis-CI
Show an Open Source Project Some Love and Start Using Travis-CIShow an Open Source Project Some Love and Start Using Travis-CI
Show an Open Source Project Some Love and Start Using Travis-CI
 

More from Alvaro Videla

Improvements in RabbitMQ
Improvements in RabbitMQImprovements in RabbitMQ
Improvements in RabbitMQAlvaro Videla
 
Data Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationData Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationAlvaro Videla
 
RabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfRabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfAlvaro Videla
 
Scaling applications with RabbitMQ at SunshinePHP
Scaling applications with RabbitMQ   at SunshinePHPScaling applications with RabbitMQ   at SunshinePHP
Scaling applications with RabbitMQ at SunshinePHPAlvaro Videla
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveAlvaro Videla
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data IngestionAlvaro Videla
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureAlvaro Videla
 
Introduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsIntroduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsAlvaro Videla
 
Rabbitmq Boot System
Rabbitmq Boot SystemRabbitmq Boot System
Rabbitmq Boot SystemAlvaro Videla
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry BootcampAlvaro Videla
 
Theres a rabbit on my symfony
Theres a rabbit on my symfonyTheres a rabbit on my symfony
Theres a rabbit on my symfonyAlvaro Videla
 
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteScaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteAlvaro Videla
 
Integrating Erlang with PHP
Integrating Erlang with PHPIntegrating Erlang with PHP
Integrating Erlang with PHPAlvaro Videla
 
Debugging and Profiling Symfony Apps
Debugging and Profiling Symfony AppsDebugging and Profiling Symfony Apps
Debugging and Profiling Symfony AppsAlvaro Videla
 

More from Alvaro Videla (16)

Improvements in RabbitMQ
Improvements in RabbitMQImprovements in RabbitMQ
Improvements in RabbitMQ
 
Data Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationData Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring Integration
 
RabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfRabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft Conf
 
Scaling applications with RabbitMQ at SunshinePHP
Scaling applications with RabbitMQ   at SunshinePHPScaling applications with RabbitMQ   at SunshinePHP
Scaling applications with RabbitMQ at SunshinePHP
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data Ingestion
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal Architecture
 
Introduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsIntroduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal Labs
 
RabbitMQ Hands On
RabbitMQ Hands OnRabbitMQ Hands On
RabbitMQ Hands On
 
Rabbitmq Boot System
Rabbitmq Boot SystemRabbitmq Boot System
Rabbitmq Boot System
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry Bootcamp
 
Vertx
VertxVertx
Vertx
 
Theres a rabbit on my symfony
Theres a rabbit on my symfonyTheres a rabbit on my symfony
Theres a rabbit on my symfony
 
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteScaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
 
Integrating Erlang with PHP
Integrating Erlang with PHPIntegrating Erlang with PHP
Integrating Erlang with PHP
 
Debugging and Profiling Symfony Apps
Debugging and Profiling Symfony AppsDebugging and Profiling Symfony Apps
Debugging and Profiling Symfony Apps
 

Recently uploaded

Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfTejal81
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.IPLOOK Networks
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxNeo4j
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applicationsnooralam814309
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and businessFrancesco Corti
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTopCSSGallery
 
Flow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First FrameFlow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First FrameKapil Thakar
 
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInThousandEyes
 
20140402 - Smart house demo kit
20140402 - Smart house demo kit20140402 - Smart house demo kit
20140402 - Smart house demo kitJamie (Taka) Wang
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud DataEric D. Schabell
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4DianaGray10
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfInfopole1
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1DianaGray10
 
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTSIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTxtailishbaloch
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdfThe Good Food Institute
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosErol GIRAUDY
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3DianaGray10
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptxHansamali Gamage
 

Recently uploaded (20)

Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applications
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and business
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development Companies
 
Flow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First FrameFlow Control | Block Size | ST Min | First Frame
Flow Control | Block Size | ST Min | First Frame
 
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
 
SheDev 2024
SheDev 2024SheDev 2024
SheDev 2024
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
 
20140402 - Smart house demo kit
20140402 - Smart house demo kit20140402 - Smart house demo kit
20140402 - Smart house demo kit
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdf
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1
 
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTSIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenarios
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx
 

Código Fácil De Testear

  • 3. Acerca de • Programador en Liip AG | Zürich • Blog: http://videlalvaro.github.com/ • Twitter: @old_sound Saturday, June 16, 12
  • 5. Acerca de Co Autor de ConillMQ en acció http://bit.ly/rabbitmq Saturday, June 16, 12
  • 6. Acerca de Co Autor de RabbitMQ in Action http://bit.ly/rabbitmq Saturday, June 16, 12
  • 8. No Soy • Gurú del testeo de aplicaciones Saturday, June 16, 12
  • 9. No Soy • Guru del testeo de aplicaciones • Abogado del TDD Saturday, June 16, 12
  • 10. Unit Testing The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. http://en.wikipedia.org/wiki/Unit_testing Saturday, June 16, 12
  • 11. Unit Tests Por definición, sólo prueban las unidades por sí solas. Por lo tanto, no descubrirán errores de integración, problemas de rendimiento y otros problemas que afectan a todo el sistema en su conjunto. http://es.wikipedia.org/wiki/Prueba_unitaria Saturday, June 16, 12
  • 12. Dogma vs. Realidad Saturday, June 16, 12
  • 16. "I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence" – Kent Beck http://stackoverflow.com/questions/153234/how-deep-are-your-unit-tests/153565#153565 Saturday, June 16, 12
  • 17. El Secreto del TDD Saturday, June 16, 12
  • 18. El Secreto del TDD Saturday, June 16, 12
  • 19. El Secreto del TDD Saturday, June 16, 12
  • 20. Algunos Libros de Kent Beck Saturday, June 16, 12
  • 21. Para escribir buenos Tests primero hay que saber programar Saturday, June 16, 12
  • 23. Los Programadores somos como los usuarios de los que tanto nos quejamos Saturday, June 16, 12
  • 24. El diseño se madura y macera con el tiempo Saturday, June 16, 12
  • 26. Separar el código puro del impuro o stateful Saturday, June 16, 12
  • 28. Funciones Puras • Devuelven datos en bases a los parámetros que aceptan Saturday, June 16, 12
  • 29. Funciones Puras • Devuelven datos en bases a los parámetros que aceptan • No modifican estado externo Saturday, June 16, 12
  • 30. Funciones Puras • Devuelven datos en bases a los parámetros que aceptan • No modifican estado externo • No producen efectos secundarios Saturday, June 16, 12
  • 31. ¿Qué tiene de malo este código? if($player->getScore() > 0) { $player->setSwizzle(7); } else { $player->setSwizzle( $player->getSwizzle() + 1 ); } http://dl.dropbox.com/u/7810909/docs/what-does-fp-mean/what-does-fp-mean/chunk-html/ar01s05.html Saturday, June 16, 12
  • 32. Version que no mezcla modificaciones de estado $newScore = $player->getScore() > 0 ? 7 : $player->getSwizzle() + 1; $player->setSwizzle($newScore); http://dl.dropbox.com/u/7810909/docs/what-does-fp-mean/what-does-fp-mean/chunk-html/ar01s05.html Saturday, June 16, 12
  • 33. El cálculo del Score se puede extraer a una función Saturday, June 16, 12
  • 34. El cálculo del Score se puede testear Saturday, June 16, 12
  • 35. Primero Escribir Código Puro Saturday, June 16, 12
  • 36. Agregar paso a paso el codigo impuro necesario Saturday, June 16, 12
  • 37. Código Fácil de Componer Saturday, June 16, 12
  • 38. Function Composition http://en.wikipedia.org/wiki/Function_(mathematics) Saturday, June 16, 12
  • 39. Function Composition http://en.wikipedia.org/wiki/Function_(mathematics) Saturday, June 16, 12
  • 41. “Many UNIX programs do quite trivial tasks in isolation, but, combined with other programs, become general and useful tools.” http://math.albany.edu/math/pers/hammond/unixphil.html Saturday, June 16, 12
  • 42. Number of open connections per IP netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n http://www.commandlinefu.com/commands/view/1767/number-of-open-connections-per-ip. Saturday, June 16, 12
  • 43. ¿Por qué no programar código de esa forma? Saturday, June 16, 12
  • 45. ¡Bienvenido a la Programación Funcional! Saturday, June 16, 12
  • 46. “Writing unit tests is reinventing functional programming in non-functional languages” http://noss.github.com/2009/02/25/writing-unit-tests-is-reinventing-functional-programming-in-non-functional-languages.html Saturday, June 16, 12
  • 47. ¿Qué nos enseña la programación funcional? Saturday, June 16, 12
  • 48. Uso Correcto de Types Saturday, June 16, 12
  • 50. ¿Qué significa ‘false|true’? Saturday, June 16, 12
  • 51. Código semánticamente correcto Saturday, June 16, 12
  • 52. Vamos a hacer la comida Saturday, June 16, 12
  • 53. Vamos a cocinar la comida Saturday, June 16, 12
  • 54. Funciones que cumplen sólo una función Saturday, June 16, 12
  • 55. Separación radical de código puro del impuro Saturday, June 16, 12
  • 56. Veamos un Ejemplo http://pastie.org/4097327 Saturday, June 16, 12
  • 57. Testeando AMQP https://github.com/videlalvaro/php-amqplib/ Saturday, June 16, 12
  • 58. Testeando queue_declare public  function  queue_declare($queue="",  $passive=false,  $durable=false,        $exclusive=false,  $auto_delete=true,  $nowait=false,    $arguments=NULL,  $ticket=NULL) {    if($arguments  ==  NULL)        $arguments  =  array();      $args  =  new  AMQPWriter();      if($ticket  !=  NULL)          $args-­‐>write_short($ticket);      else          $args-­‐>write_short($this-­‐>default_ticket);      $args-­‐>write_shortstr($queue);      $args-­‐>write_bit($passive);      $args-­‐>write_bit($durable);      $args-­‐>write_bit($exclusive);      $args-­‐>write_bit($auto_delete);      $args-­‐>write_bit($nowait);      $args-­‐>write_table($arguments);      $this-­‐>send_method_frame(array(50,  10),  $args);      if(!$nowait)          return  $this-­‐>wait(array("50,11"));        //  Channel.queue_declare_ok } Saturday, June 16, 12
  • 59. Testeando queue_declare class  AMQPChannel  extends  AbstractChannel {    public  function  __construct($connection,  $channel_id=null,  $auto_decode=true)    {        $this-­‐>frameBuilder  =  new  FrameBuilder();        if  ($channel_id  ==  null)  {            $channel_id  =  $connection-­‐>get_free_channel_id();        }        parent::__construct($connection,  $channel_id);        if  ($this-­‐>debug)  {            MiscHelper::debug_msg("using  channel_id:  "  .  $channel_id);        }        $this-­‐>default_ticket  =  0;        $this-­‐>is_open  =  false;        $this-­‐>active  =  true;  //  Flow  control        $this-­‐>alerts  =  array();        $this-­‐>callbacks  =  array();        $this-­‐>auto_decode  =  $auto_decode;        $this-­‐>x_open();    }    /*  ...  más  métodos  y  propiedades  omitidos  */ } Saturday, June 16, 12
  • 60. Testeando queue_declare public  function  queueDeclare($queue,  $passive,  $durable,  $exclusive,   $auto_delete,  $nowait,  $arguments,  $ticket) {    $args  =  new  AMQPWriter();    $args-­‐>write_short($ticket)              -­‐>write_shortstr($queue)              -­‐>write_bit($passive)              -­‐>write_bit($durable)              -­‐>write_bit($exclusive)              -­‐>write_bit($auto_delete)              -­‐>write_bit($nowait)              -­‐>write_table($arguments);    return  $args; } Saturday, June 16, 12
  • 61. Testeando queue_declare public  function  queue_declare($queue="",  $passive=false,  $durable=false,                                                                  $exclusive=false,  $auto_delete=true,  $nowait=false,                                                              $arguments=NULL,  $ticket=NULL) {    $arguments  =  $this-­‐>getArguments($arguments);    $ticket  =  $this-­‐>getTicket($ticket);    $args  =  $this-­‐>frameBuilder-­‐>queueDeclare(                                              $queue,  $passive,  $durable,  $exclusive,  $auto_delete,  $nowait,  $arguments,  $ticket);        $this-­‐>send_method_frame(array(50,  10),  $args);    if  (!$nowait)  {        return  $this-­‐>wait(array("50,11"));        //  Channel.queue_declare_ok                                } } Saturday, June 16, 12
  • 62. Testeando queue_declare public  function  testQueueDeclare() {    $expected  =  "x00x00x03foox00x00x00x00x00";    $args  =  $this-­‐>frameBuilder                              -­‐>queueDeclare(      'foo',  false,  false,  false,  false,  false,  array(),  0 );    $this-­‐>assertEquals($expected,  $args-­‐>getvalue()); } Saturday, June 16, 12
  • 63. ¿Cómo aplico esto al mundo real? Saturday, June 16, 12
  • 64. ¿Cómo aplico esto al mundo real? • Ver la charla de Ricard “Servicios en Symfony2” Saturday, June 16, 12
  • 65. ¿Cómo aplico esto al mundo real? • Ver la charla de Ricard “Servicios en Symfony2” • Muchos servicios especializados y desacoplados Saturday, June 16, 12
  • 66. ¿Cómo aplico esto al mundo real? • Ver la charla de Ricard “Servicios en Symfony2” • Muchos servicios especializados y desacoplados • Clases que cumplen sólo una función Saturday, June 16, 12
  • 67. “Inside every well- written large program is a well-written small program” http://www.linfo.org/q_programming.html Saturday, June 16, 12
  • 69. ¡Gracias! Álvaro Videla http://twitter.com/old_sound http://github.com/videlalvaro http://www.slideshare.net/old_sound Saturday, June 16, 12