<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Loveneesh Singh on Medium]]></title>
        <description><![CDATA[Stories by Loveneesh Singh on Medium]]></description>
        <link>https://medium.com/@tuberatemarv?source=rss-6ac6e66d1b79------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ht5iepmx7ys0se4OA-jDXQ.png</url>
            <title>Stories by Loveneesh Singh on Medium</title>
            <link>https://medium.com/@tuberatemarv?source=rss-6ac6e66d1b79------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 09:04:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tuberatemarv/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding test data patterns]]></title>
            <link>https://tuberatemarv.medium.com/understanding-test-data-patterns-32f9557b306a?source=rss-6ac6e66d1b79------2</link>
            <guid isPermaLink="false">https://medium.com/p/32f9557b306a</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[test-driven-development]]></category>
            <category><![CDATA[patterns]]></category>
            <category><![CDATA[junit]]></category>
            <dc:creator><![CDATA[Loveneesh Singh]]></dc:creator>
            <pubDate>Mon, 14 Jun 2021 19:03:44 GMT</pubDate>
            <atom:updated>2021-06-14T19:03:44.665Z</atom:updated>
            <content:encoded><![CDATA[<p>Tests are like a safety net for code and when we write more test suites covering edge cases it helps in increasing the quality and credibility of the code. On the flip side, a clean and readable test is also important as it makes finding bugs and adding new test cases easy. However, over the span of time the test suites grow along with the code and it becomes very hard to read or to add new test cases leading to confusion.</p><p>The readability of the test is as important as the readability of the code which is being developed and pushed to production. In this blog, we are going to learn about one of the most common problems which we face while writing a test i.e creation of a class specifically a data class, and how we can handle multiple creations of the data classes cleanly. We will also be covering different patterns/methods of creating data classes cleaner which can be reused along with the pros and cons of each pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D-VBVX2d8SCVY1sa" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>To start with, we will take the class Person.java. “Person” is a data class or POJO which has an all argument constructor and instance variables that are encapsulated. We will be using the Person Class to write tests and explore different patterns of instantiation of the class. To write our tests we will be using the Junit 5 framework with Java.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cde084f60c1027872e91b954456186ed/href">https://medium.com/media/cde084f60c1027872e91b954456186ed/href</a></iframe><h3>Individual object creation</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4c772ecdd091d8da2d8f6695bb69142/href">https://medium.com/media/b4c772ecdd091d8da2d8f6695bb69142/href</a></iframe><p>The first pattern is a commonly used pattern for writing tests i.e creating an instance of the class inside the test method itself.</p><p>Like, we see in the example of PersonTest class where we want to test the validity of a person’s email. To do this, we create a person class instance with a valid email and call <em>isValidEmail() </em>method which returns <em>true</em> if the email is valid and <em>false</em> if the email is invalid.</p><p>The test <em>shouldReturnTrueForCorrectEmail()</em> only tests a happy scenario but, we would also want to test one scenario where we want to check what <em>isValidEmail()</em> returns when the email is incorrect. For that, we need to create one more Person class instance with an invalid email and assert the return of <em>isValidEmail() </em>method. If we want to test different variations of invalid email for example email without “@” sign, email without “.” sign. We have to create multiple instances of the Person class with invalid emails.</p><blockquote>Person person = new Person(1, “John”, “johngmail.com”, “888888”, “888888”, null, null);</blockquote><p>This actually creates a lot of noise in the code, if the data classes or the POJOs are not easy to create and takes a lot of constructor parameters. Since it requires the creation of multiple instances of the same class with the parameter being changed according to the test objective it will result in a lot of redundant and unreadable code.</p><p>Ideally, creating a data class in the test gives more clarity if the class getting instantiated in the test is small (taking fewer parameters to create), in this case, we might not see any major problems. But if the POJO class is too big then creating an instance of the classes will be complex and time-consuming.</p><h3>Test data utilities</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c95548b6a1aecc9fd41735303e3ca7f0/href">https://medium.com/media/c95548b6a1aecc9fd41735303e3ca7f0/href</a></iframe><p>The next pattern which we are going to explore is a “Test utilities” pattern where we create small test utilities for the creation of the object. We move all the default values inside the utility method so that we have to pass fewer parameters or the parameter we wish to change for the test and the utility handles the creation of the object.</p><p>Like in this case, the address can have a default value <em>null</em> as we are testing only the email of the person. So, we can create a utility function which can only take the email or fewer parameter and help in the creation of the object.</p><p>In a language like Kotlin where method parameters can have a default value. This utility function can be more enhanced to write something like:</p><blockquote>fun aPerson(name: String = “name”, email:String = “email@email.com”) : Person</blockquote><p>By doing this we can selectively pass only the field we require to test or change and other variables will use default values as provided.</p><p>This really helps a developer in creating instances of POJOs in the test class. It also improves the aesthetics of the code making it appear cleaner and readable. This pattern goes very well with Kotlin but in the case of java, we are still passing multiple parameters, and over a period of time as we want to test more property of the person class we will end up creating multiple utilities or creating the same utility with multiple parameters which again defeats the purpose of creating test utilities.</p><h3>Test data builder for class</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe829a6979f72d9287926d86ca3f4af5/href">https://medium.com/media/fe829a6979f72d9287926d86ca3f4af5/href</a></iframe><p>To avoid creating multiple utilities or utilities with multiple parameters. We can explore the Test data builder pattern.</p><p>Test data builder like Java builder pattern provides the capability to build the object by setting each property. They can be enhanced to provide a default instance that can be used if we do not want to change any of the property of the class.</p><p>For example, in this case, we want to build a person with an invalid email to test the validity of the email. Then for the Person class, we just change the value of email. The builder provides a default implementation for the Person class and any property which we want to change can be done in the specific test. For example, we want to set the property email in this test. We can do it in the following way:</p><p><em>PersonBuilder.defaultBuilder(). email(“99999”).build()</em></p><p>This returns a person with an invalid email. It makes the creation of the test data much simpler and easier. Also helps in keeping the test clean and easy to understand, as for each test we can just change one value and test only that value which eventually results in modular and smaller level tests.</p><p>However, with all the pros this pattern has, it also comes with an overhead of creating a builder in the test code which can be a lengthy task to create and maintain. As we can see in the example, test builders can be very big depending on the number of instance variables the POJO will have. Also, if there are a lot of POJOs in the project we can end up creating a lot of builders for it.</p><p>So, do we need a builder for every class in the project? The answer will be no. we need to be very careful before creating a builder for every POJO or model, we can choose to create a builder for only those classes which have a lot of instance variables. For small classes, in-place creation of the object in the test class makes the code more readable and helps us reducing the overhead of creating a builder for it.</p><h3>Lombok test data builders</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8a2b2058a72f245d92d5b63255d2422/href">https://medium.com/media/d8a2b2058a72f245d92d5b63255d2422/href</a></iframe><p>Lombok is a code generation library that allows a developer to create getter, setter, constructor, and utilities over a class without worrying about writing and maintaining the code for that class.</p><p>We can use this property of Lombok to actually create builders for our tests more easily. It will help us to keep the test clean and easy to maintain in a long run.</p><p>Like in the example, PersonTestData class <em>extends</em> Person and the <em>@Builder</em> annotation can be used to create a builder of type PersonTestData, this can be used anywhere we need Person class as it is a child class of Person. By, using this pattern we do not have to worry about writing code to construct the builder but it can be all autogenerated by the Lombok annotation.</p><p>This helps us to write clean and more meaningful tests. A scenario where this approach might not be suitable is when reflection is used. As the class returned by the builder is PersonTestData class and not the Person class. So, whenever we are using this pattern we can not use it with spring entity, or java reflections.</p><p>All these patterns are beneficial in their own ways, so to use one over the other is a judgment call that needs to be evaluated and then taken before writing the test. If the class is small and easy to create maybe the “Individual object creation” pattern will do the job. If there are a lot of variables to change and test “Lombok builders” can help to write better tests. The end goal is to write clean and maintainable tests along with clean code.</p><p>Thanks !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32f9557b306a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 key tips to crack CKAD certification]]></title>
            <link>https://blog.devgenius.io/5-key-tips-to-crack-ckad-certification-d2dd4dbad971?source=rss-6ac6e66d1b79------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2dd4dbad971</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[ckad]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[Loveneesh Singh]]></dc:creator>
            <pubDate>Tue, 01 Dec 2020 05:08:00 GMT</pubDate>
            <atom:updated>2021-01-01T10:28:19.756Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I have successfully cleared <a href="https://www.cncf.io/certification/ckad/">Certified Kubernetes Application Developer (CKAD)</a> certification and I would like to share my experience and learning tips and tricks as well as resources that helped me earn the CKAD badge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Wt8ztutZk-pYEKvyK_NedA.png" /></figure><p><strong>#Tip 1 : Know Your Enemy Well [EXAM SYLLABUS]</strong></p><p>In order to prepare for the exam the first step should be knowing the syllabus well. I’m going to list out the key chapters which will help you prepare for the certification, a brief version of the syllabus is also present on the CNCF <a href="https://www.cncf.io/certification/ckad/">page</a>.</p><ul><li><strong>Core Concepts</strong> : <em>Pod , Replica Set , Deployment, Namespaces</em></li><li><strong>Configuration</strong>: <em>Command Arguments , Environment Variables, Config map , Secrets , Security Contexts , Node Affinity , Taint and tolerations, Service Account</em></li><li><strong>Multi-Container Pods</strong>: <em>Sidecar , Ambassador, Adapter</em></li><li><strong>Observability</strong>: <em>Liveness Probe , Readiness Probe , Logging , Monitoring</em></li><li><strong>Pod Design</strong>: <em>Labels , Selectors, Job , Cron Job , Deployment Strategy</em></li><li><strong>Services &amp; Networking</strong> : <em>Network Policies , Services, Ingress</em></li><li><strong>State Persistence</strong> : <em>PersistentVolume, PersistentVolumeClaim, Volume Mount, Storage Class , StatefulSets</em></li></ul><p>You can also go through the below hands on training course available on Udemy which I personally found to be very useful.</p><p><a href="https://www.udemy.com/share/1013BQAEAeeVpXTHwA/">Kubernetes Certified Application Developer (CKAD) Training</a></p><p><strong>#Tip 2 : Prepare Your Arsenal [Use imperative commands whenever practicing]</strong></p><p>Every resource in kubernetes can be created by using yaml files. Like if you want to create a pod using yaml. You can use declarative command to create it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97d6744c1e35a73c6ea28393c6cccb8f/href">https://medium.com/media/97d6744c1e35a73c6ea28393c6cccb8f/href</a></iframe><p>But sometimes it can get very messy to create yaml file from scratch as you can run into a lot of problems like indentation and using wrong keys. These type of problems can consume a lot of time also they are hard to debug. So, rather than creating yamls from scratch try using imperative <a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/imperative-command/">commands</a> this will save a lot of time and help you to pace up.</p><p>For an example to create a pod with and image you can use:</p><pre>kubectl run &lt;pod_name&gt; --image=&lt;image_name&gt;</pre><p>This can help you to create pod without creating pod.yaml and if you want to add more things into yaml you can use dry-run command to get yaml out of this imperative command. Example</p><pre>kubectl run &lt;pod_name&gt; --image=&lt;image_name&gt; -o yaml --dry-run=client</pre><p>This command can give you pod yaml which you can obviously edit and save some precious time during your exam.</p><p>I found a very good resource to practice imperative commands in kubectl . This git repository has a lot of examples of kubectl imperative commands.</p><p><a href="https://github.com/dgkanatsios/CKAD-exercises">GitHub - dgkanatsios/CKAD-exercises: A set of exercises to prepare for Certified Kubernetes Application Developer exam by Cloud Native Computing Foundation</a></p><p><strong>#Tip 3 : Friends In Need [Make use of kubenetes.io when ever stuck]</strong></p><p>During the exam you are only allowed to access these links <a href="https://kubernetes.io/docs/">https://kubernetes.io/docs/</a>, <a href="https://github.com/kubernetes/">https://github.com/kubernetes/</a>, <a href="https://kubernetes.io/blog/">https://kubernetes.io/blog/</a> and their subdomains. More instructions and tips on the exam can be found on this <a href="https://docs.linuxfoundation.org/tc-docs/certification/tips-cka-and-ckad">link</a>.</p><p>There are some object in kubernetes which can not be created by imperative commands and obviously one has to create yaml file for it. And as you know writing a yaml is a daunting task as it consumes most of your time. So best tip will be to get familiar with kubernetes.io find all the places where you have to look whenever you are stuck. Do not use google search, make use of kubernetes <a href="https://kubernetes.io/docs/">docs</a> and copy the yaml content to create different kubernetes objects. Do not try to right yaml on your own unless you are an expert in it.</p><p>One more things which can help you while writing yaml files is kubectl explain commands. If you want to know what are the keys at a certain level and what value it contains, you can use kubectl explain command to find it. For example if you want to know what are the keys containers can have can have in a pod.yaml , you can easily find it out using the following command.</p><pre>kubectl explain pod.spec.containers</pre><p>kubectl explain command works like a documentation command for a lot of kubernetes object and even it explain what value the key can hold and what is the type of the value.</p><p><strong>#Tip4 : All Or Nothing [Try to attempt as many question as you can]</strong></p><p>In CKAD exam some questions are too easy while others can take some time to solve. And all the questions are randomly arranged so make sure you read all the question and do not waste time on single question.</p><p>The way i follow is if the question is not getting through even after 2 tries i flag them and move forward so that i can try other questions. Try to attempt all question in the exam do not spend more time on a single question you can always flag them and move forward to the next one. Maybe for you the upcoming question can be much easier to solve.</p><p>One more thing you should always keep in mind is to always read the question carefully and do the changes in right places as asked in the question. Do not forget to read the info part of the question which might offer some hint.</p><p><strong>#Tip5 : Hustle [Practice well]</strong></p><p>This tips can help you to channelize your effort and time well but at last practice is the key. Make sure you practice as much as you can . For people who are new to kubernetes take a month and go through the entire syllabus. You can also setup a cluster on Google Kubernetes Engine(GKE), <a href="https://www.katacoda.com/">katacoda</a> or any preferable kubernetes cloud provider for free for practice. For people who already have some experience with kubernetes try to master imperative commands that can be the deal breaker. At last you should be able to create , delete , debug resources in kubernetes to pass this exam.</p><p>Do get familiar with an editor (vim or nano) whichever you are comfortable with, try not use any text editor or any IDE while practising for exam.</p><p>This exam is indeed very rewarding and helps you to stand out as an proficient application developer. So get set and start preparing for the exam.</p><p>All the Best!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*nc_e1BRE_nKIqbOAO3fKlA.gif" /><figcaption>Clap below to recommend this article to others👏👏</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2dd4dbad971" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/5-key-tips-to-crack-ckad-certification-d2dd4dbad971">5 key tips to crack CKAD certification</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[StepVerifier vs block in Reactor]]></title>
            <link>https://medium.com/swlh/stepverifier-vs-block-in-reactor-ca754b12846b?source=rss-6ac6e66d1b79------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca754b12846b</guid>
            <category><![CDATA[software]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[reactor-project]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Loveneesh Singh]]></dc:creator>
            <pubDate>Sun, 10 May 2020 11:22:50 GMT</pubDate>
            <atom:updated>2020-06-10T11:39:01.102Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been working with the reactor library for quite a while now and this blog is about a dilemma that every developer might face while writing tests for non-blocking reactive code. This blog will help you to set some rules in your team or squad on whether to use block or StepVerifier based on specific cases. Hence, this will clear some doubts about which one to use where and when.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eoKK7uexiEUw1wGE" /><figcaption>Photo by <a href="https://unsplash.com/@nordwood?utm_source=medium&amp;utm_medium=referral">NordWood Themes</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Before reading this blog you must be familiar with Mono &amp; Flux in the reactor library and also have some prior experience of writing tests using StepVerifier or block, in order to understand the comparison between both and to relate your experiences with it.</p><p>Let&#39;s first try to build an understanding of what block or StepVerfier is and what it provides in terms of testing a reactive code.</p><p><strong>block()</strong></p><p>A block is an API that is defined on both Mono and Flux, It internally calls subscribe and immediately blocks the execution of flow until a signal(output) is received. It is not recommended to use a block in the main production code as it blocks the main thread, due to which it can cause a cascading effect where all further calls to the method are blocked and one will have to wait for the execution of the previous subscription on that method. Blocking the main thread in the reactor by doing a subscribe or block takes away all the benefits of writing non-blocking reactive code. Still, if someone wants to write a block in a reactive world, they can use the <em>subscribeOn()</em> API on Mono/Flux which takes Schedulers(eg. elastic) that makes the execution of Mono/Flux on different scheduler threads and execute it asynchronously without blocking the main thread.</p><p>But except for the production source code, developers can choose to write tests by using a <em>block()</em> API as it is not going to affect the performance of the application in any way.</p><p>Using <em>block() </em>API to write tests for a Mono and Flux:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd67833e2b89a5b64786c200ecef6980/href">https://medium.com/media/dd67833e2b89a5b64786c200ecef6980/href</a></iframe><p>Above is a small example of how you can use a block to write a test for reactive publishers. In this example, a Mono of Person[0|1] and Flux of Person[n] are blocked for the output signal, and then the output is tested.</p><p>To test the exceptions one can use a <em>block()</em> API on Mono/Flux that executes until the error signal is received and throws the exception. Therefore, in the case of Mono that is either empty or one, the exception can be caught and asserted with the output of the method, but in case of Flux which is a continuous stream of data performing a <em>block()</em> operation, will lead to subscription of all the elements which are emitted by the Flux that will result in an error. As we can see in the example given below, only the error that is thrown is tested and we further won’t be able to test the data emitted before the exception.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc97cc12ae9d8b564573d8165f81b1c5/href">https://medium.com/media/dc97cc12ae9d8b564573d8165f81b1c5/href</a></iframe><p>We have seen examples of how one can use the block method to wait for the signal of publisher Mono/Flux and write tests on the basis of the output. But, there are some limitations for using <em>block()</em> to test reactive code and they are the following:</p><ul><li>How to test Flux which is emitting a stream of data. [As we have seen above if there is an exception in between the data stream, <em>block()</em> returns the exception and we are not able to test data before exception]</li><li>Delays can not be tested using block [ <em>Mono.delay(Duration.ofSeconds(12))]</em></li><li>Testing the Publishers which are subscribed to different schedulers using <em>subscribeOn() </em>API<em> </em>can not be tested using a block.</li></ul><p>In a nutshell, a <em>block() </em>API can only test the output of the publisher by subscribing to it, but it cannot test the reactive aspect of the code written using the reactor library. To test the reactive aspect of the code, the reactor provides a test library that has a declarative way of writing reactor tests using StepVerifier.</p><p><strong>StepVerifier</strong></p><p>StepVerifier is provided by reactor test dependency that supports the testing of the reactive aspects of the code. It provides a declarative way to expect events that will occur on the subscription of an async publisher and it only gets triggered after terminal methods have been invoked i.e <em>verify()</em>. With the StepVerifier, we can define our expectations of published elements in terms of what elements we expect and what happens when our stream completes. StepVerifier subscribes to the publisher and consumes data as a stream from the emitting Mono/FLux.</p><p>Following is an example of using StepVerifier to write tests for a Mono and Flux:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdd778f8cd0a04a47e192f12e31241bd/href">https://medium.com/media/fdd778f8cd0a04a47e192f12e31241bd/href</a></iframe><p>StepVerifier provides rich API to test delays and subscriptions on different schedulers using <em>withVirtualTime() </em>API,<em> </em>which was not possible to test in case of a <em>block()</em>. StepVerifier also supports writing tests for the publishers that emit errors. In the case of Flux, using a block() API for the testing of data is not possible where the data is emitted before a publisher has thrown an exception. Unlike block() API, in StepVerifier we can expect the publisher to emit data until the exception is thrown, as we have known that the publisher is closed after an exception is thrown.</p><p>Following is an example of StepVerifier to test Exception:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d46a05a8e87484690d05a3a1288527d/href">https://medium.com/media/3d46a05a8e87484690d05a3a1288527d/href</a></iframe><p>As we have seen that StepVerifier is not only testing the output of the reactive code but it is also testing the reactive aspect of the code. It tests how the async publisher emits data and behaves when it is subscribed by a subscriber. With all the ease that StepVerifier provides for testing reactor code it also has some shortcomings with the syntax, for writing tests. For the assertion of a simple output Mono[0|1], StepVerifier makes assertion noisy and quite difficult to read. One has to even remember to write a <em>verify() </em>in the chain at the end, else the test will pass without execution of the code.</p><p>As you can see that there are pros and cons of both <em>block()</em> and<em> StepVerifier</em> testing patterns. Hence, it is necessary to define a pattern or set of rules which can guide us on how to use StepVerifier and block().</p><p>In order to decide which patterns to use, we can try to answer the following questions which will provide a clear expectation from the tests we are going to write:</p><ul><li>Are we trying to test the reactive aspect of the code or just the output of the code?</li><li>In which of the patterns we find clarity based on the 3 A’s of testing i.e Arrange, Act, and Assert, in order to make the test understandable?</li><li>What are the limitations of the <em>block()</em> API over <em>StepVerifier</em> in testing reactive code?</li><li>Which API is more fluent for writing tests in case of Exception?</li></ul><p>If you try answering all these questions above, you will find the answers to “what” and “where”. So, just give it a thought before reading the following answers:</p><ul><li>block() tests the output of the code and not the reactive aspect. In such a case where we are concerned about testing the output of the code, rather than the reactive aspect of the code we can use a <em>block()</em> instead of <em>StepVerifier</em> as it is easy to write and the tests are more readable.</li><li>The assertion library for a block() pattern is better organized in terms of 3 A’s pattern i.e Arrange, Act, and Assert than StepVerifier. In StepVerfier while testing a method call for a mock class or even while testing a Mono output one has to write expectation in the form of chained methods, unlike assert which in my opinion decreases the readability of the tests. Also, if you forget to write the terminal step i.e <em>verify()</em> in case of StepVerifier,<em> </em>the code will not get executed and the test will go green. So, the developer has to be very careful about calling verify at end of the chain.</li><li>There are some aspects of reactive code that can not be tested by using block() API. In such cases, one should use StepVerifier when we are testing a Flux of data or subscription delays or subscriptions on different Schedulers, etc, where the developer is bound to use StepVerifier.</li><li>To verify exception by using block() API you need to use <em>assertThatThrownBy </em>API<em> </em>in assertions library that catches the exception. With the use of an assertion API, error message and instance of the exception can be asserted. StepVerifier also provides assertions on exception by expectError() API and supports the assertion of the element before errors are thrown in a Flux of elements that can not be achieved by block(). So, for the assertion of exception, StepVerifier is better than a block() as it can assert both Mono/Flux.</li></ul><p>I have formed all these opinions through gaining experience by writing tests for reactor code. And this should not be assumed as a standard for writing tests for the reactor. Choosing an appropriate pattern totally depends upon the team&#39;s comfort with the assertions library. If the team is not comfortable enough with assertions they can choose to stick with StepVerfier there is no harm in it. This blog guides you to gain knowledge of when to use what depending on the situation.</p><p>Thank’s for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca754b12846b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/stepverifier-vs-block-in-reactor-ca754b12846b">StepVerifier vs block in Reactor</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pipeline as code in Jenkins]]></title>
            <link>https://tuberatemarv.medium.com/pipeline-as-code-in-jenkins-8a011331dd95?source=rss-6ac6e66d1b79------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a011331dd95</guid>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[techniques]]></category>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Loveneesh Singh]]></dc:creator>
            <pubDate>Mon, 10 Dec 2018 19:31:28 GMT</pubDate>
            <atom:updated>2020-05-12T18:44:36.930Z</atom:updated>
            <content:encoded><![CDATA[<p>Pipeline as code is a technique which defines that how we can write CI/CD build or deployment pipeline with code which can be fed to make pipeline automatically and which can even be version controlled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bhKRlwpaQz3we5FI" /><figcaption>Photo by <a href="https://unsplash.com/@realaxer?utm_source=medium&amp;utm_medium=referral">tian kuan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Before talking about how to follow this technique to make it more efficient and easy to adapt, let&#39;s just understand why we want to do it? Jenkins, GO CD, Team City or Circle CI are few tools to do continuous integration and continuous delivery. These tools help in continuously integrating the source code and act as a safety net for the developer as the code gets tested by the pipeline after every check-in to the code. It makes a developer life easier as they do not have to worry about a buggy code getting through to production and code is always ready to be deployed.</p><p>In Jenkins, making pipeline is easy as one has to either use Jenkins syntax or write groovy scripts in the pipeline. Generally, teams follow this approach to build a new pipeline as it is easy and fast. But as the team size increases, the number of pipelines also increases as they have to build/deploy more projects. Building a pipeline in such a scenario can be easy using the traditional way of building pipelines manually. But modification, testing or maintenance can become a nightmare if the team has hundreds of pipeline. As some pipelines like building source code (Builds) can be similar, so to create a new build pipeline one can simply copy paste the pipeline script in new pipelines for all other similar build pipelines, but what if they want to add a new stage in all build pipeline? It will require them to copy that stage pipeline script in every pipeline and if there are hundreds of them then it will require a lot of manual effort to be done and will be error-prone, so there is a need for templatization of similar pipelines such that it can make the modification of the pipeline easy. As we talked about modification it also comes with an overhead of maintenance. If there is a change in pipeline script no one will get to know what got changed or who changed it, that makes the pipeline script buggy and testing of the script is also not possible in such scenario, and if it is a breaking change there is no way to revert back to a stable version as the pipeline script is not versioned.</p><p>Due to these problems of scaling similar builds (templatization), testing pipeline code, and to make the pipeline code version controlled we use this technique called ‘Pipeline as code’.</p><p>There are various ways of following this technique :</p><ul><li>Jenkins files</li><li>Jenkins job builder tool</li></ul><p>In this blog, I will be talking about the Jenkins Job Builder tool. To read about how to do Pipeline as Code using Jenkins file you can check out this <a href="https://jenkins.io/doc/book/pipeline-as-code/">link</a>.</p><h3><strong>Jenkins Job Builder</strong></h3><p>Jenkins job builder is a tool which takes yaml or json configuration and uses them to configure Jenkins pipeline. A developer can write the configuration for the Jenkins pipelines and with that configuration JJB(Jenkins Job builder) tool will configure specific pipelines in Jenkins.</p><p>Let us see how to create a pipeline using JJB(Jenkins job builder).</p><p>job-template can be used if you have several jobs that are similar, as all similar jobs can point to a single template by specifying the name of the template which is mentioned in the project configuration. For example, a normal build job that can be similar for all teams will have similar build stages, so all the build jobs can point to the same template. Any modification to the template will automatically reflect in all pipelines sharing the template.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4e4c2f60ec67c62bd0159a1066b3f5d/href">https://medium.com/media/b4e4c2f60ec67c62bd0159a1066b3f5d/href</a></iframe><p>A project is like a template which is referred by the job-template, the project collects all the relatable jobs together and gets the values passed from the job. It takes all the job-templates configured with a specific job name and the templates are then applied to configure new Jenkins pipeline.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e554edfff7bb3b3573f3837b6d97c290/href">https://medium.com/media/e554edfff7bb3b3573f3837b6d97c290/href</a></iframe><p>To make a pipeline in Jenkins one has to run the JJB tool with these yaml configurations as its parameters and the tool will populate all the pipelines mentioned in the jobs. Example command</p><pre>jenkins-jobs --conf etc/jenkins_jobs.ini-sample update jobs/samplejobs.yaml:templates/sampletemplates.yaml</pre><p>Jenkins Job Builder updates, deletes &amp; creates pipeline on the basis of the configuration provided. This configuration can easily be stored in a version controlled system like git and a developer can run the tool over every check-in in the code.</p><p>JJB also makes the modification of pipelines very easy as for adding one stage in multiple pipelines one just need to do changes in the template which gets reflected in every other job which is using that template and with the modification being done, it can also be tracked like all the changes in the pipeline code is done with code check-in which can be reverted easily in case if the code breaks or if there is an issue with the code. Debugging issues also become very easy and we can even write tests for all the pipeline code which was untested before. The most important benefit that pipeline as code brings is if one wants to shift to a new instance of Jenkins it can easily be done as the code resides in a git repository and can easily be applied to make new Jenkins pipeline instantly.</p><p><strong>Pros of using ‘Pipeline as Code’</strong></p><ul><li>Easy to create, update &amp; delete pipelines</li><li>Version controlled (can detect which version had the bug)</li><li>Test pipeline code</li><li>Easy to configure similar pipelines</li><li>Easy to migrate to new Jenkins instance</li></ul><p>This technique helps in scaling CI/CD and make it more reliable. To read more about JJB refer to this <a href="https://docs.openstack.org/infra/jenkins-job-builder/">link</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a011331dd95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Breaking down the Monolith]]></title>
            <link>https://tuberatemarv.medium.com/breaking-down-the-monolith-bf5572295afc?source=rss-6ac6e66d1b79------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf5572295afc</guid>
            <category><![CDATA[cqrs]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[ddd]]></category>
            <category><![CDATA[monolithic]]></category>
            <category><![CDATA[event-driven-systems]]></category>
            <dc:creator><![CDATA[Loveneesh Singh]]></dc:creator>
            <pubDate>Thu, 05 Apr 2018 06:13:48 GMT</pubDate>
            <atom:updated>2020-05-12T18:46:32.473Z</atom:updated>
            <content:encoded><![CDATA[<p>So, before I start telling you about the problems we faced and how we solved them, I would like you folks to get familiar with the ‘Loki’ of coding world. Loki! sounds strange in a coding blog right? Many company’s unknowingly or knowingly are still using this mischievous style of coding which I tell you might be the cause of their downfall, so if you still holding on to those old memories (pun intended) be very scared coz’ professor Doom is very near.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H3Na6YnI_RhXWY6j" /><figcaption>Photo by <a href="https://unsplash.com/@iurte?utm_source=medium&amp;utm_medium=referral">Iker Urteaga</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The topic which I’m trying to describe here is <strong>Monolithic Architecture (a large single upright block of stone, especially one shaped into or serving as a pillar or monument or the foundation stone. Any changes in the foundation is going to produce devastating results which will be too costly to handle).</strong> This is a legacy style of coding architecture which constraints the developers and chains them down from their imagination. In the below few lines I’ll explain how this acts as a roadblock to a quality style of software development.</p><p>I came across this term recently when I saw this legacy system in work for one of our client. It contained a UI (User Interface) which connects to a back-end and do the read/write on the database to get the work done. Seems to be a simple CRUD based model to me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*f3iKuJ-b1nz7kthPmEll3Q.png" /></figure><p>A CRUD model in itself is an efficient and workable way of software development, considering the size of your project is small and does not require multiple call to the backend or database. As the number of domains continue to grow with the project demands, it created a lot of fuss among the developers as all the projects shared the same <strong>Repository</strong>. The simultaneous changes made in code by different developers were a pain to handle and monitor by the respective teams during the development phase.</p><p>The three major issues that are associated with this Monolith which I discovered while working on the project are:</p><p>i. <strong>Scalability</strong>: This is one of the serious problems which restrict the developers from writing efficient and necessary codes. Even a small change in the code can result in chaos as it has to be synced with all the other teams working on the Repository.</p><p>ii. <strong>Maintainability: </strong>With the number of projects increasing, maintaining the code in a single repository was a much bigger task than development itself. Not only you are supposed to develop an efficient working code you also have to take care of the bugs and errors introduced by others.</p><p>iii. <strong>Deployment/Delivery: </strong>This whole fiasco makes the deployment process a walk on thrones. For the deployment, you need to coordinate with all the teams working on the repo, sync all your code and then you can proceed with deployment. This might take longer than usual time which effects the delivery of the project.</p><p><strong>The magic potion for the dying code (Initial Solution):</strong></p><p>On thorough analysis of the code we found that all the domains in the project were identical and were working on the same principle. So, we finally decided to experiment with one of the domains and tried separating it from the parent Repository to its own repo. As we expected the changes worked perfectly, now all the domains were separated with different repo’s and they shared the same database, thus we achieved the solution for the three major problems associated with current Monolith described above.</p><p>As of now our domains are no longer co-dependent, the only common thing they share are the UI (User Interface) and the database. So, from now on any and every request through the UI goes to the respective domain and does the required transactions on the database to get the work done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61B4RicW8XidFJciNctBrg.png" /></figure><p><strong>The Blunder (problems with the new code):</strong></p><p>Now after doing all the changes and separating the codebase in the nuclear modules, as the number of domains were increasing the overhead on the database increased and it slowed down a lot which was an adverse effect after the separation. As all the domain was querying the database flooding it with reads/writes which became a major problem to handle. For complex query it was hard to optimise the read and write of data from database.</p><p>One more problem which stood in front of us was the lack of communication between the domains. In simpler words if one domains require to access the functionality/capability (inform change in domain) of some other domain it’ll be restricted.As the domains are separated and deployed as different systems. Other domains can not poll the database infinite times to get to know about the change in other domain. As it will further slow down the single database.</p><p>Now the situation in hand was much worse than what it was earlier. The domains still require communicating with others which again introduces the Monolith, the thing we were trying to avoid for so long.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*70Z0ZTvwUghJo0jBfnKNmg.png" /></figure><p><strong>The Saviour (The Ultimate Solution)</strong></p><p>Then I came to know about concepts of CQRS &amp; Event Driven architecture.</p><p>CQRS stands for (Command Query Responsibility Segregation). The change that CQRS introduces is to split conceptual model into separate models for updating(write) and display(read), which it refers to as Command and Query. All the write is done by the command and read happens by query. Both the logically separated command and query sits inside a domain and have one small database in common or can be implemented to have different database for command and query. Benefit of implementation of CQRS is you can optimize the read side of the system separately from the write side and teams can scale it separately. So, basically each domain will have its own database which is a small set of data required for the domain and thus separated from the big giant database. It encounters the problem of multiple domain which were reading/writing into a common database. Still we have dependency between the system which need to solve, that can be done using Event Driven Architecture.</p><p>Event Driven Architecture is when a system sends event messages to notify other systems of a change in its domain. A key element of event message is that the system doesn’t really care much about the response. Often it doesn’t expect any answer at all, other domains interested in the Event Picks it up and do the processing. The communication happens over Event bus(Queues) like (Kafka/ActiveMQ).</p><p>These two terminologies solved all the problem that existed. Now domain do not have to share a single database and have their own database with separated read and write, thus increasing the performance of the system. And all the communication between the domains can be done through <strong>Events</strong>. Now, each domain publishes the event on event bus which can be listened by other domains or the domains which are interested in the event . It gives domains a capability to be built independently and to be scaled and deployed separately . As of now no service depends on other service and all the domain communicate through events.Which finally resolved the problem we had with the monolith design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6UwpY8PNLQABCBPxLJlIA.png" /></figure><p><strong>Words of Caution</strong></p><p>As CQRS has a lot of pros for a complex system it also comes with a lot of cons. It introduces a lot of complexity in the system. Not every system fits in the mold of CQRS . Thus one should be cautious about using it . Like for a simple domain model in which you want to read/write data from the database and there is only one domain. One do not want to play around with the complexity of CQRS and Event Driven Architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf5572295afc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>