Pages

Thursday, June 18, 2020

Javing is now on Medium too.

Dear readers of Javing. Recently I decided to publishing also on medium. Don't worry I will never stop publishing here but the reason I decided to expand to the also popular medium platform is because it would increase the visibility of my company. I would kindly ask you if you are a regular reader of Javing, to please follow Javing also on medium. This is the link to the Javing profile on medium: https://javing-uk.medium.comonce you get there you should see the follow option.

Also I would like to thank you all for reading my articles during all this years and I am looking forward to continue Javing for many more years.

Warm regards to everyone.

Sunday, June 7, 2020

Ubuntu aliases backup

Just some of the aliases I use more freequently. I thought to back them up here in a blogpost.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# alias management

alias a='alias'

alias ae='nano ~/.bashrc'

alias s='source ~/.bashrc'



#docker

alias dR='ds;dr;dp;dip;dri;dl'

alias dc='docker-compose up -d --build'

alias de='sudo dockerd &'

alias di='docker images -a'

alias dip='docker images purge'

alias dl='docker ps -s -a'

alias dn='docker network create'

alias dp='docker system prune --volumes && docker network prune'

alias dpa='docker ps -a'

alias dps='docker ps -s'

alias dr='docker rm $(docker ps -a -q)'

alias dri='docker rmi -f $(docker images -a -q)'

alias ds='docker stop $(docker ps -a -q)'

alias dst='docker start'

alias gdc='g;dc'

alias gx='./gradlew build -x test'



# gradle and maven

alias g='./gradlew clean build --rerun-tasks --no-build-cache'

alias gt='./gradlew -q tasks'

alias mci='mvn clean install'

alias mc='mvn clean'

alias mcp='mvn clean package'



# java

alias homej11='export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/;echo $"JAVA_HOME set to:";echo $JAVA_HOME;s'

alias homej8='export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/;echo $"JAVA_HOME set to:";echo $JAVA_HOME;s'

alias j11='sudo update-java-alternatives -s java-1.11.0-openjdk-amd64;jv;homej11'

alias j8='sudo update-java-alternatives -s java-1.8.0-openjdk-amd64;jv;homej8'

alias jv='java -version'



# other

alias l='ls -CF'

alias la='ls -A'

alias ll='ls -alF'

alias w='cd ~/workspace'


Saturday, May 23, 2020

docker-compose: setup of spring boot app and it's dependant services

In this video I show how to create an image of a spring boot app that was previously built with gradle and use that image alongside all the other services it depends on. Docker compose is a very useful tool that can help us reduce the complexity of configuring services to be run on docker.


Wednesday, March 25, 2020

Tuesday, March 24, 2020

Monday, March 9, 2020

Test creation order

Just digging into some old papers today, I found this old note. I think I did screenshot this long ago from a video by Sandro Mancuso. 

1. Class name: The class name is post fixed with Should. This is a pattern that was introduced by Sandro in his lectures. Since tests are probably already in the test package, we don't need to know post fix them with the word test, this class name is more BDD friendly and serves as good documentation.

2. Method name: Is concise and it explains what it does without revealing implementation detail. The words are separated with underscore so that it is easier to read than camel case in a first glance.

3. Assertion written first: By writing the assertion first we reduce the risk of introducing assumptions and over engineer. It helps keeping the code minimal and growing it progressively.

4. Action: Once  e have our assertion we will write the action. This maybe seems counter intuitive
but as you will notice, as we are writing the assertion and the action, the code is not compiling, this will force us to code the minimum required to make the test compile.

5. Setup: The last step is to add the setup. With this approach we forced our brain to focus on the behaviour and not on the state. This focus on behaviour is the key for growing the code gradually. Thinking on state first rather than behaviour can lead to assumptions and missed requirements.

This is a very interesting approach which has a lot of benefits. What do you think?

Friday, February 28, 2020

Intro to Apache Kafka with Spring

In this application I am creating a simple java micro service that consumes from a kafka topic.
This implementation uses the spring-kafka framework. The code for this example can be found here: https://github.com/SFRJ/offerskafka


Sunday, February 23, 2020

IntelliJ ultimate embedded http client

Did you know that IntelliJ ultimate has an embedded http client that you can use to sent requests to your app? There's no need for external tools like curl or postman, you can just use IntelliJ's endpoints tab. Also this requests can be saved as http files and be used on tests.


Tuesday, February 18, 2020

Kafka F.A.Q

In here a few questions around Kafka that may appear on interviews. As I will collect more, I will add them to this post. Other Java related interview questions, can be found here:
http://javing.blogspot.com/2018/12/java-developer-interview-questions.html

In the context of Kafka, what does back pressure mean?
It means that a slow consumer should be capable of handling throughput coming from a fast producer.

Do you know any solution(other than increasing partitions) to deal with consumers back pressure? 
- Increasing partitions
- The consumer signals to the producers that they are sending the data to fast(reactive streams can do this)
- Buffering 

Name one advantage and one disadvantage of Kafka?
advantage: using Kafka can reduce the amount of integrations needed in a large ecosystem of applications. This reduction of integrations often results operational cost savings for the company.
disadvantages

disadvantage: order in which events arrived in a multiple partitions scenario is not guaranteed. Using timestamps can help consumers understand the order. If the cluster is being distributed across different time-zones, the event may also need to carry some sort of unique identifier so that alongside the timestamp, the consumer can understand the order. 

Can race conditions happen in Kafka and how can we prevent them?
Race conditions with Kafka consumers can happen and one of the main reasons is that in multi partition scenarios, the order of the events is not guaranteed. In order to guarantee ordering timestamps and/or unique identifiers is needed.

Saturday, February 15, 2020

Restful app demo and explanation (recruitment code challenge)


Today I did a code challenge that a recruiter gave me. Is for a vacancy at a London company.
I thought to record a demo explaining the code that i implemented and some of my thoughts, just to have here for future reference. I uploaded the code to this repo: https://github.com/SFRJ/offers
In the requirements it says to publish in github, so if I am allowed to publish in github, maybe I am allowed to also publish on the blog and on youtube :)

Here the demo:



bonus using vavr(formerly javaslang)
The exercise said that I could choose any tool I like, I was thinking in doing vavr but since is not so well known maybe the reviewers don't like it. But just for myself I decided to modify the code to use vavr and upload it in a separate repository on github(https://github.com/SFRJ/offersvavr). This a very short video with some of the changes i did to introduce vavr:



Update(morning after)
When I was uploading the video in youtube i was just previewing and I noticed there was a little bug. I added tests for it and fixed it. Interesting, this situation made me thing about the importance of QA(Quality Assurance). I did not write automated acceptance tests but AAT are basically programmatic quality assurance. Maybe with AAT I woulda catch that but earlier. Doing the technique used to bring QA before code implementation is called ATDD(Acceptance Test Driven Development). Link to article written in this blog some time back on the topic: 


I uploaded this other video with the explanation of the bug:

 I just noticed that in the video I didn't explain that I refactored that overridden cancel method I was talking about at the end, since that method extraction was not really needed if I call again the repository in both get and cancel methods.

Tuesday, February 11, 2020

Design Decisions

I was practising a Kata I haven't done in a while because I wanted to add a recording to the new Page I created dedicated to TDD Katas. The Kata in question was the Roman Numerals Kata (From Roman to Arabic).

After doing the Kata I ended up with this implementation:



This is fine, the solution worked but I just didn't like that those two nested loops seemed a bit of a lot of complexity. Probably not the best solution from the point of view of performance. I wanted to try something else. So I deleted that code and without deleting the tests I wrote this:



To me this seemed a bit better and probably faster. Optimisations are something that we should always postpone. Remember the saying?

Make it run, then make it nice, then make it fast.

Early optimisations can lead to unwanted over-engineering and some other problems. TDD teaches us that we need to grow our code gradually. But then how can we just refactor to something completely different than what we just got?

Once we have written all our tests and we are happy with our refactoring, the tests will act as our documentation, so even if we were to delete all the code and just leave the tests, we could recreate the code. So that is what I did initially to create that second implementation.

After observing the new implementation and compare it to the previous one, I decided to TDD to see if I could get to the code in the second implementation. I discovered that at the point where I was doing the refactoring after making the test for number 6 pass, here was the place where I could make a design decision and choose not to extract an enum and instead try something else.

This time the Kata has once more proven that TDD is not just capable of making safer code but also drive the design even when we are looking for a faster solution than the one we have.


Here the video for that Kata:
 

Sunday, February 9, 2020

Javing.uk launched company website

Recently my company which has the same name as this blog launched it's website under the domain:
https://www.javing.uk/

In the following weeks I will be re-organising a bit the content of the blog and also it's look and feel so that it is more aligned with the company colours and font. I will continue to blog as I often do with the only difference that this blog will now be the official blog of www.javing.uk


Saturday, February 8, 2020

TDD Katas

I am planning to re-organise some of the content of the blog. From now own TDD Katas will no longer be posted as blog posts, instead they will be added to the page "TDD Katas" on this blog under the following url: http://javing.blogspot.com/p/tdd_9.html

Share with your friends