Archivio mensile 30 July 2018

Katzenjammer del 29 luglio 2018

Eclissi di luna, perchè era rossa ? E con cosa abbiamo multato Google? Andiamo su Marte o su Venere e come siamo messi con i satelliti Galileo? Tutto questo è passato su Katzenjamemr del 29 luglio 2018 a radiocittaperta.it . Ascoltate il podcast

  1. Song 2 – Blur
  2. B.Y.O.B. – System Of A Down
  3. Luna – Lucio Leoni
  4. Moonage Daydream – David Bowie
  5. The Killing Moon – Echo & the Bunnymen
  6. Ideaplatonica – Bluvertigo
  7. Italian Polaroid – La Municipàl
  8. L’Etat C’est Moi – The Blinders
  9. Tziganata – Litfiba
  10. Come Home – Placebo
  11. Flying in a Blue Dream – Joe Satriani
  12. Of Moons, Birds & Monsters – MGMT
  13. Love Me Like You Do – Ellie Goulding
  14. Viszlát nyár – AWS
  15. Mexican Standoff – Elbow
  16. Bold – Jackie Cohen
  17. Sugar for the Pill – Slowdive

How to: emulate SQS Amazon queue for testing purpose

This article first appear on Medium here

Amazon Simple Queue Service (SQS) is a fully managed message queuing service from Amazon.

If you want to integrate it, you may also want to test if it works. SQS has probably a sandbox to test it but if you don’t want to get stuck searching for it, or you don’t want to get crazy with login procedures, you can use a mock service that acts as an SQS queue* .

Why do we need this? Why can’t we use a simple Wiremock that always responds “200, OK”?

You can’t do it because the response of SQS is a dynamic response dependent from the request, and it’s based on some MD5 calculation.

 
MD5 calculation

What we have done is an extension of Wiremock that always responds something like “200, OK”, with all the fields correctly calculated for SQS. It was both easy and not-so-easy, because every easy task it’s never a “It’s just …“.

In this case, it was more of a “it’s just not enough to…” — just spinning a docker container up or adding a class to the classpath would simply not do.

How To, Step by step guide

First of all we need to define a class that extends theResponseDefinitionTransformer class with two easy to implement methods:

applyGobally that returns true, means that “all the requests will receive this response”.

getName it’s a method that Wiremock needs. Then you must implement the real method that responds correctly, the method is transform

calculateResponse does the dirty job, and it’s a dirty method (I know it could be refactored…)

This method gets the body of the request, splits it because it’s an url-like body, and then calculates the MD5 of all the attributes, types and values according to SQS documentation.

updateLengthAndBytes it’s a method to update the MD5 calculation.

To be honest, we also created an additional class SimplifiedMessageAttribute:

After this step, you can build an XML document (the implementation of this is not in this post because it‘s cumbersome) and include the calculated fields (md5OfMessageBody and md5OfMessageAttributes). For other fields, requestId and messageId, we used hard coded values. The final result should be something like this:

 
Response Example for SQS

After this, you can build your project and obtain a jar.

How can we integrate this into Wiremock?

That’s not so easy. What I’ve found is that you have to move your jar in the same path of the Wiremock jar and start the Wiremock with:

Wiremock has no plugin mechanisms, so what you are doing with this command is:

with -cp “*” you are telling Java “take all the jars in this folder”

… your main class is here: com.github.tomakehurst.wiremock.standalone.WireMockServerRunner

… and use this extension: your.package.name.SQSMock

From this point onwards, you can use it directly, build a docker container or whatever you want.

IT is not an easy task and, from my point of view, every layer added to simplify things is a new topic to learn and understand.

During this journey we have learnt about SQS, wiremock, mvn, unit test and obviously Java. I want to thank:

  • Giuseppe Gaeta (Tech Lead)
  • Matteo Moci (Software Dev Engineer II)
  • Camillo Quatrini (QA Evangelist)
  • Tiziana Battiston (Travel Agencies Manager, proofreader)

Ref:

* There are some restrictions: such service doesn’t work for not-string attributes.

Come simulare una coda SQS Amazon per esigenze di test

Questo articolo appare per la prima volta su Medium qui

Amazon Simple Queue Service (SQS) è un servizio di accodamento dei messaggi completamente gestito da Amazon.

Se vuoi integrarlo, potresti anche verificare se funziona. SQS ha probabilmente una sandbox per testarlo, ma se non vuoi rimanere bloccato a cercarlo o non vuoi impazzire con le procedure di accesso, puoi utilizzare un servizio fittizio che funge da coda SQS* .

Perché ne abbiamo bisogno? Perché non possiamo usare un semplice Wiremock che risponda sempre “200, OK”?

Non puoi farlo perché la risposta di SQS è una risposta dinamica dipendente dalla richiesta e si basa su alcuni calcoli MD5.

 

 
Calcolo MD5

Quello che abbiamo fatto è un’estensione di Wiremock che risponde sempre qualcosa come “200, OK”, con tutti i campi calcolati correttamente per SQS. È stato sia facile che non così facile, perché ogni compito facile non è mai un “È solo …”.

In questo caso, era più un “non è sufficiente per…” — semplicemente far ruotare un contenitore docker o aggiungere una classe al classpath semplicemente non funzionava.

Come fare, guida passo passo

Prima di tutto dobbiamo definire una classe che estenda la classe ResponseDefinitionTransformer con due metodi facili da implementare:

applyGoballyche restituisce true, significa che “tutte le richieste riceveranno questa risposta”.

getName è un metodo di cui Wiremock ha bisogno. Quindi devi implementare il vero metodo che risponde correttamente, il metodo è transform

calculateResponse fa il lavoro sporco, ed è un metodo sporco (so che potrebbe essere refactored…)

Questo metodo ottiene il corpo della richiesta, lo divide perché è un corpo simile a un URL e quindi calcola l’MD5 di tutti gli attributi, i tipi e i valori in base alla documentazione SQS.

updateLengthAndBytes è un metodo per aggiornare il calcolo MD5.

Ad essere onesti, abbiamo anche creato una classe aggiuntiva SimplifiedMessageAttribute:

Dopo questo passaggio, puoi creare un documento XML (l’implementazione di questo non è in questo post perché è ingombrante) e includere i campi calcolati (md5OfMessageBody e md5OfMessageAttributes). Per gli altri campi, requestId e messageId, abbiamo utilizzato valori hardcoded. Il risultato finale dovrebbe essere qualcosa del genere:

Esemip di risposta SQS

Successivamente, puoi costruire il tuo progetto e ottenere un jar.

Come posso integrarlo su Wiremock?

Non è così facile. Quello che ho scoperto è che devi spostare il jar nello stesso percorso del jar Wiremock e avviare il Wiremock con:

Wiremock non ha meccanismi di plugin, quindi quello che stai facendo con questo comando è:

con -cp “*” stai dicendo a Java “prendi tutti i jar in questa cartella”

… la tua classe principale è qui: com.github.tomakehurst.wiremock.standalone.WireMockServerRunner

… e utilizza questa estensione: your.package.name.SQSMock

Da questo punto in poi, puoi usarlo direttamente, creare un contenitore docker o quello che vuoi.

L’IT non è un compito facile e, dal mio punto di vista, ogni strato aggiunto per semplificare le cose è un nuovo argomento da imparare e capire.

Durante questo viaggio abbiamo imparato a conoscere SQS, wiremock, mvn, unit test e ovviamente Java. Voglio ringraziare:

  • Giuseppe Gaeta (Tech Lead)
  • Matteo Moci (Software Dev Engineer II)
  • Camillo Quatrini (QA Evangelist)
  • Tiziana Battiston (Travel Agencies Manager, proofreader)

Ref:

* Ci sono alcune restrizioni: tale servizio non funziona per attributi non stringa.

Katzenjammer del 8 luglio 2018

Pasticche, Trump, bitcoin, computer e musica. Questo è stato katzenjammer del 8 luglio 2018

  1. Hold Unknown – Dinosaur Jr.
  2. Pain – The Soft Moon Remix – Boy Harsher The Soft Moon
  3. Glory – Cold Cave
  4. 400 Lux – Lorde
  5. Wanna Be Loved – John Legend
  6. Dark Dark in the Night – Hang the DJ
  7. Massimiliano Cranchi – Anna
  8. Serenity Now – Wax Fang
  9. Minus – Daniel Blumberg
  10. Romance – Shoeb Ahmad
  11. So Far Under – Alice In Chains
  12. La vita è una – Il Muro Del Canto
  13. With Animals – Mark Lanegan Duke Garwood
  14. Eyes Like Pearls – The Cora
  15. Goldrake – Alessio Caraturo
  16. Get Your Shirt – Radio Edit – Underworld Iggy Pop
  17. Can’t Stop – Red Hot Chili Peppers
  18. Mile End – Pulp
  19. Thanks 4 Nothing – Nilüfer Yanya
  20. Virginia in the Rain – Dave Matthews Band

Katzenjammer del 1 luglio 2018

Giocattoli NAZI, il terremoto al gol del Messico, Ruspanda, Batterie elettriche, Unamuma e tante altre cose oltre a tanta favolosa musica. 

  1. The Breach – Dustin Tebbutt
  2. Out Of My Mind – The Killers
  3. Rotary Dial – Ghost and Pals
  4. Produktivitet – Sista Bossen
  5. Libri Di Sangue – Radio Mix – Frankie HI-NRG MC
  6. Impossibile – Cosmo
  7. Maps – Yeah Yeah Yeahs
  8. False Alarm – The Head and the Heart
  9. Undone – The Sweater Song – Weezer
  10. The Rover – Interpol
  11. Domani è un altro giorno (feat. Daniele Coccia Paifelman) – Piotta Daniele Coccia Paifelman
  12. Make It Real – Suuns
  13. Push It – Boom Boom Satellites Mix – Garbage BOOM BOOM SATELLITES
  14. The Sorrow Tree – EastWest Session – Moby
  15. Black Rainbow Sound (feat. Brix Smith) – Menace Beach
  16. Istambul – Litfiba
  17. Heaven – Emeli Sandé
  18. Wonderwall – Remastered – Oasis