<?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 Mustafa Onur Aydın on Medium]]></title>
        <description><![CDATA[Stories by Mustafa Onur Aydın on Medium]]></description>
        <link>https://medium.com/@mustafaonuraydin?source=rss-3ad28ff81a26------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*txHovH3gpbaxbqyNRPoc7A.jpeg</url>
            <title>Stories by Mustafa Onur Aydın on Medium</title>
            <link>https://medium.com/@mustafaonuraydin?source=rss-3ad28ff81a26------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:53:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mustafaonuraydin/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[Couchbase Integration Testing for Golang via Testcontainers]]></title>
            <link>https://medium.com/trendyol-tech/couchbase-integration-testing-for-golang-via-testcontainers-25b906bc2c0d?source=rss-3ad28ff81a26------2</link>
            <guid isPermaLink="false">https://medium.com/p/25b906bc2c0d</guid>
            <category><![CDATA[testcontainer]]></category>
            <category><![CDATA[integration-testing]]></category>
            <category><![CDATA[couchbase]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[tdd]]></category>
            <dc:creator><![CDATA[Mustafa Onur Aydın]]></dc:creator>
            <pubDate>Mon, 21 Dec 2020 15:11:38 GMT</pubDate>
            <atom:updated>2020-12-21T15:15:21.843Z</atom:updated>
            <content:encoded><![CDATA[<h4>Integrate Couchbase with Golang via Singleton Pattern and Test Driven Development approach</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*7iaXA1RWJFQ07BqwByYQEw.png" /></figure><p>In Trendyol, we are developing microservice projects with different programming languages and technologies. The Golang is one of them. We are following test driven development approach to development process. Because of that, we are focusing to apply test driven development approach when we are learning a new programming language. Test driven development is the only first step. We are following SOLID principles, caring readable, maintainable clean code and architecture, apply design patterns, four key metrics, and more :) If you are interested too these approach like us, you can be a part of the team. <a href="https://jobs.lever.co/trendyol?lever-via=VwanwiCD9G">You can see available roles click over here.</a> Join us!</p><h4>Why we need integration tests?</h4><p>The first step of applying test driven development is unit test. However, in some cases, unit tests are not enough. In some cases, you need to write component tests for understanding your units working together right. What if we are dependent on some third-party unit or a system like database, messaging queues etc. In these cases, integration testing will helps. You can simulate cases the same as production.</p><p>Testcontainers is the known solution for writing integration tests. You can start easily your third party dependent platforms as a docker container. But there is no preconfigured couchbase implementation in the current testcontainers golang solution.</p><h4>Couchbase Integration Test for Golang</h4><p>Testcontainers is allowing to run any docker image. In the official couchbase docker image is not configured via docker environment variables. You can initialize via user interface or command-line interface which is provided from couchbase. A configurable couchbase docker image with environment variable will be so useful when writing integration tests with testcontainers. For that reason, I’m going to use my customized couchbase docker image which can initialize via environment variables.<br><a href="https://github.com/Trendyol/couchbase-docker-image-for-testcontainers">This image is open source and you can access it here over github.</a> And also the image is using over <a href="https://github.com/HofmeisterAn/dotnet-testcontainers">dotnet-testcontainers</a> pre-configured Couchbase solution which is contributed from me.</p><p>You can pull the image over docker hub like the following;</p><blockquote>docker pull docker.io/trendyoltech/couchbase-testcontainer:6.5.1</blockquote><p>Default values of environment variables are following;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1fea03eb7325196d1cb48d77776f868/href">https://medium.com/media/a1fea03eb7325196d1cb48d77776f868/href</a></iframe><p>You can override environment variables for customizing. Here is an example of couchbase integration test over golang via testcontainers;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd6f7a7867e0d92032bec6c31c70d7be/href">https://medium.com/media/bd6f7a7867e0d92032bec6c31c70d7be/href</a></iframe><p>In the above example, testcontainers generic container is starting Couchbase over Golang background context with customized environment variables. After that, you need to defer terminating of container. This will guarantee for you to destroy container after test. In this example, test expecting and implementation that returns Couchbase’s Cluster object. After that test can assert is Couchbase created with the expected configuration and bucket.</p><p>In my <a href="https://github.com/Trendyol/couchbase-docker-image-for-testcontainers">Couchbase docker image</a>, you can see “couchbase-dev started” log if everything is fine.</p><blockquote>wait.ForLog(&quot;couchbase-dev started&quot;).WithStartupTimeout(45 * time.<em>Second</em>)</blockquote><p>Please be sure that you have enough resources for running Couchbase container which should be a minimum that is defined over docker image environment. Otherwise, container will not start and the test will fail after the startup timeout which you defined as above.</p><p>Test driven development approach steps are following the picture. Now the fail test is ready. Let’s write code and be sure that will be working on production fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Snw2QZJe4s-5z42yk4AIA.png" /></figure><h4>Integrate Couchbase for Golang</h4><p>Let’s check first how we can connect Couchbase and open bucket. <a href="https://docs.couchbase.com/go-sdk/current/hello-world/start-using-sdk.html#hello-couchbase">Here is an example from Couchbase documentation.</a></p><pre>func main() {<br>   cluster, err := gocb.Connect(&quot;localhost&quot;, gocb.ClusterOptions{<br>         Username: &quot;User&quot;,<br>         Password: &quot;password&quot;,<br>   })<br>   if err != nil {<br>      panic(err)<br>   }<br>}</pre><p>This is the first information we need. Now, this is the right time to consider that how the function will create cluster only one time. Right answer is “Singleton Pattern” but how? Golang provides “<strong>Once</strong>” object which is under sync package and Once is an object that will perform exactly one action. No need to worry about race conditions! The solution is following;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/393d496c8fa1818e20f06a07b6417cf0/href">https://medium.com/media/393d496c8fa1818e20f06a07b6417cf0/href</a></iframe><p>In the above code, we are creating a cluster like Couchbase’s documentation advice. “<strong>Once</strong>” is provides that the code block runs only one time. In the first call, this function creates a cluster and assigns over the global variable. After that function returns the same cluster in every call.</p><p>This is a sample application. You can make connection variables as an environment variable and you can override over on test. You may need to consider edge and boundary cases depending on your solution requirements like timeout etc.</p><p>You can access the sample project from the following gitlab repository;<br><a href="https://gitlab.com/golang-testcontainers/integration-testing-couchbase-for-golang">https://gitlab.com/golang-testcontainers/integration-testing-couchbase-for-golang</a></p><h4><strong>Conclusion</strong></h4><p>This article will help to understand writing integration tests with test driven development approach for golang via testcontainers. You can write any integration test for any depend platform via following steps in this article. Testcontainers are useful for end-to-end tests too.</p><p>You can run your tests over pipeline like Gitlab pipeline. You can define a blocker step before deployment when tests fail. Because of that no one can destroy your solution accidentally. Tests are written in once but runs unlimited. This will helps you sleep more comfortable at night :)</p><p>Thanks for reading this article! Do not hesitate to make criticism with comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25b906bc2c0d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/couchbase-integration-testing-for-golang-via-testcontainers-25b906bc2c0d">Couchbase Integration Testing for Golang via Testcontainers</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated Integration Testing over Gitlab CI/CD for Dotnet Core via Testcontainers]]></title>
            <link>https://medium.com/trendyol-tech/automated-integration-testing-over-gitlab-ci-cd-for-dotnet-core-via-testcontainers-b18c7f81e65f?source=rss-3ad28ff81a26------2</link>
            <guid isPermaLink="false">https://medium.com/p/b18c7f81e65f</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[testcontainer]]></category>
            <category><![CDATA[integration-testing]]></category>
            <category><![CDATA[automated-testing]]></category>
            <category><![CDATA[gitlab-ci]]></category>
            <dc:creator><![CDATA[Mustafa Onur Aydın]]></dc:creator>
            <pubDate>Sun, 02 Aug 2020 09:33:17 GMT</pubDate>
            <atom:updated>2020-08-03T08:32:57.877Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1 : Integration Testing with Dotnet Testcontainers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9fNXvhJUTxM-ufedmCeC6w.png" /></figure><p>I love Java there is no doubt. In my career of engineering i used so many different programming languages, tools even microprocessors. After passed 7 year, almost all years i was mostly a part of some Java based projects as a backend developer. The passed year in my journey with Trendyol, i had chance to discover Golang, improve my frontend skills with ReactJS when i was working as a Java developer. In last 3 month, i catch a chance to discover Dotnet Core via C#. I’m grateful to Trendyol for giving chance to us trying different technologies.</p><p><strong>What you can find in this article series?</strong></p><p>I will try to explain, how to apply automated testcontainers approach with dotnet-testcontainers like in Java testcontainers. This article will be two part. First part will be around, how to use docker containers for integration tests for Dotnet Core. Second part will be around how to automate testing over Gitlab CI/CD pipeline.</p><p><strong>What you can not find in this article?</strong></p><p>In this article, i will not compare programming languages tools etc like “Java is better than C#” :) The main aim of article explaining of applying test practices. The best programming languages/tools is not certain and depends your human resources. The truth is practices are same for different platforms.</p><h4>Part 1 : Integration Testing with Dotnet Testcontainers</h4><p>Why we need integration tests? You can find tons of article about this question. The shortest answer is being sure that your development is compatible with your production environment.</p><p>In last three month, i was working in Charge project in Trendyol. The project responsibility is to manage cancel and claim processes. To achieve success, we need to be sure that our Charge micro service is covering all edge and boundary cases. In this scenario end to end tests very useful.</p><p>There is a pretty good solution for java which is called testcontainers. I decided to apply this practice over dotnet-core. After my research i saw some alternative ways to writing dockerize test containers over dotnet. <br>There is a pretty good solution from Andre Hofmeister which is called, <a href="https://github.com/HofmeisterAn/dotnet-testcontainers"><strong>dotnet-testcontainers</strong></a><strong> </strong>. This library supports lots of functionality for creating docker containers for the integration tests. <br>Dotnet-testcontainers has folowing pre-configured solutions;</p><ul><li>CouchDB (couchdb:2.3.1)</li><li>MsSql (server:2017-CU14-ubuntu)</li><li>MySql (mysql:8.0.18)</li><li>PostgreSql (postgres:11.5)</li><li>Redis (redis:5.0.6)</li><li>RabbitMQ (rabbitmq:3.7.21)</li></ul><p>In our micro service we need <strong>Couchbase</strong> as a test container. I developed a pre-configured Couchbase container over dotnet-testcontainers. It took time when i was developed. Also there was challenges to use Couchbase as a testcontainer with minimal resources.</p><p>I love open source ❤️ . And also <a href="http://github.com/trendyol">Trendyol</a> advices to us contributing open source community too.</p><p>Andre’s dotnet-testcontainers library is an open source project. I decided to contribute dotnet-testcontainers and i contacted with Andre. He is really kind person. He accept our contributing request and we discussed how we can improve dotnet-testcontainers with new features.</p><p>After all, <strong>I contributed</strong> with <strong>Couchbase</strong> <strong>test container </strong>to dotnet-testcontainer ! 🎉 🎉 🎉 🍾 🍾 🍾</p><p>You can use my Couchbase test container solution after <a href="https://www.nuget.org/packages/DotNet.Testcontainers/1.4.0-beta.20200723.17">1.4.0-beta.20200723.17</a> version of dotnet-testcontainers. Thank you Andre for this amazing library!</p><p>Here is a sample, how to use dotnet-testcontainers with pre-configured Couchbase container.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1264d16f0b604d9729b24849b7bebf4/href">https://medium.com/media/b1264d16f0b604d9729b24849b7bebf4/href</a></iframe><p>You can create a Couchbase docker container easily like above. This code, creating a cluster with “Administrator” username and “password” password. You can define initial bucket like above “Charge”parameter. Now you can start Couchbase test container with following code;</p><pre>await couchbase.StartAsync();</pre><p>After that, you can write your tests which is using Couchbase repository.</p><p>If you need more bucket, you can create like following;</p><pre>await couchbase.CreateBucket(&quot;Customer&quot;);</pre><p>This function creating bucket with 128mb bucket memory. If you need to customize than you can create bucket like following;</p><pre>await couchbaseTestcontainer.CreateBucket(&quot;Customer&quot;, 256);</pre><p>Now we are able to write integration tests for Couchbase.</p><p>Here is a sample application over gitlab which i wrote;<br><a href="https://gitlab.com/dotnet-testcontainers/couchbase-testcontainers-sample">https://gitlab.com/dotnet-testcontainers/couchbase-testcontainers-sample</a></p><p>Lets check;<br>There is a provider class for using Couchbase with dependency injection.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/686f940e016059282861fce7bd6ec2de/href">https://medium.com/media/686f940e016059282861fce7bd6ec2de/href</a></iframe><p>Now we can develop a repository like following;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8422200c41ee8e7f5d2aa2958416b7c7/href">https://medium.com/media/8422200c41ee8e7f5d2aa2958416b7c7/href</a></iframe><p>Now we can write our tests for DocumentsRepository. Unfortunately, over dotnet core we need to do something more for use dependency injection over integration tests. Following ItContext class is creating and starting CouchbaseTestcontainer and initializing dependency injection context for tests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15d92fc19a1e401980b6ea8b34e6015a/href">https://medium.com/media/15d92fc19a1e401980b6ea8b34e6015a/href</a></iframe><p>After that, we should define a collection for use that ItContext as a fixture;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4016f6d096a2581b0303b8837a6d1569/href">https://medium.com/media/4016f6d096a2581b0303b8837a6d1569/href</a></iframe><p>After all we are ready to write tests like following.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9c108b95d51c08ceefbe950bd2ec4b1/href">https://medium.com/media/d9c108b95d51c08ceefbe950bd2ec4b1/href</a></iframe><p>After that [Collection(“ItContext”)] definition, we are able to use dependency injection context. <br>You can access the sample project from following gitlab repository;<br><a href="https://gitlab.com/dotnet-testcontainers/couchbase-testcontainers-sample">https://gitlab.com/dotnet-testcontainers/couchbase-testcontainers-sample</a></p><p><strong>Conclusion</strong></p><p>This article will help to understand writing integration tests for dotnet core via dotnet-testcontainers. The second part will focus more automatize integration tests over Gitlab CI/CD pipelines with docker near docker. The right known wrong is docker in docker is same docker near docker. Actually is not. Please keep follow for more details.</p><p>Thanks for reading this article! Do not hesitate to make criticism with comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b18c7f81e65f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/automated-integration-testing-over-gitlab-ci-cd-for-dotnet-core-via-testcontainers-b18c7f81e65f">Automated Integration Testing over Gitlab CI/CD for Dotnet Core via Testcontainers</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Boot Async Executor Management with ThreadPoolTaskExecutor]]></title>
            <link>https://medium.com/trendyol-tech/spring-boot-async-executor-management-with-threadpooltaskexecutor-f493903617d?source=rss-3ad28ff81a26------2</link>
            <guid isPermaLink="false">https://medium.com/p/f493903617d</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-framework]]></category>
            <category><![CDATA[thread-pool]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[asynchronous]]></category>
            <dc:creator><![CDATA[Mustafa Onur Aydın]]></dc:creator>
            <pubDate>Wed, 24 Jul 2019 05:28:21 GMT</pubDate>
            <atom:updated>2019-09-28T10:48:35.537Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>1. Challenge : </strong>In Trendyol, we are developing a micro service project for integrate some third party systems. In this integration, we should consume some pageable api’s in every two hours. In this progress micro service will consume api over than 200.000 times. Every api call using resources and managing these progress going to complex. We can not consume api in single thread, because every 2 hour starting new scheduler and progress should finish immediately. In this way we are choosing to use Asynchronous programming for this progress.<br>In fact looks like simple to call every api request in asynchronous, but there is a threshold. If we start to consume over than 200.000 request in same time, every thread consume resources and if resources not enough system will block. In dockerized application workflow, your micro service container will down and start again when system block and not responding. This mean you will lose the state of your application and you should start progress again. Because of these you should make your asynchronous threads scaleable and non blocking.</p><p><strong>2. Summary :</strong> In this article, i will try to explain important points of managing Spring Boot <strong>@Async</strong> feature with <strong>ThreadPoolTaskExecutor</strong>.</p><p>Enabling to asynchronous functionality in Spring Boot is very easy with using @EnableAsync annotation over any of Spring Boot configuration class. <br>But managing is async not easy like this, you should analyze your application of how many threads will be running at same time and scalability. After that you should define an Executor (java.util.concurrent.Executor) implementation for manage your @Async functions.</p><p><strong>3. Overview : </strong>Spring’s TaskExecutor interface extends from java.util.concurrent.Executor interface. You can access TaskExecutor implementations from following link;<br><a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#scheduling-task-executor-types">https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#scheduling-task-executor-types</a></p><p>In this article we will review <strong>ThreadPoolTaskExecutor</strong> implementation.</p><p>For activating your custom executor, you should create an <strong>AsyncConfigurer</strong> implementation and override getAsyncExecutor() function. Otherwise Spring will use it’s default Executor implementation and your configuration will not be active.</p><p>Sample of ThreadPoolTaskExecutor definition is like following picture. We will follow this definition in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*FmGCytv1eJzV6SqMw9jfPA.png" /></figure><p>ThreadPoolTaskExecutor contains following concepts;</p><p><strong>Core Pool Size : </strong>Core pool size is defines minimum paralel threads can run at same time. In our sample, CORE_POOL_SIZE = 75 and this mean, our application can increase paralel running threads up to 75. If our application need more thread over than 75, new threads will be added into queue.</p><p><strong>Queue Capacity : </strong>Queue is using when all core pool are filled. Threads will be scalable to maximum pool size when queue is full. In our application, let’s imagine 75 threads running at same time and also 75 threads more in queue. Totally we have 150 threads. Pool size will be increased until maximum pool size for each thread over 150.</p><p><strong>Maximum Pool Size : </strong>Maximum pool size defines maximum parallel threads can run at same time. In our sample MAX_POOL_SIZE = 100 and this mean, our application can be increase to 100 parallel running threads when queue is full.</p><p>After all, we should decide what will happen to more thread when maximum pool and queue is full. <br>Some approach is define queue is Integer.<em>MAX_VALUE, </em>but i’m not suggested this approach. Maximum defined queue is means never will be filled and your application will never scale from core pool size to maximum pool size. <br>Also some other approach is core pool and maximum pool size set same value and using queue maximum. This means fixed size thread pool without scalability. You can not decide your cpu and memory utilization.</p><p>Now let’s decide what will happen to more threads when maximum pool and queue is full. In Spring’s default , threads will be rejected with ThreadPoolExecutor.AbortPolicy and you lose new threads. For scalable application i’m suggested to use ThreadPoolExecutor.CallerRunsPolicy. This policy provides to us scalable queue when maximum pool is filled.</p><p>ThreadPoolTaskExecutor has following policies definitions;</p><p><strong>ThreadPoolExecutor.AboutPolicy</strong> : Rejecting the thread with throwing RejectedExecutionException. You will lose the thread.<br><strong>ThreadPoolExecutor.CallerRunsPolicy : </strong>The thread invokes itself on rejected pool. You will not lose the thread. This policy like increasing queue capacity. You can manage your application with this policy.<br><strong>ThreadPoolExecutor.DiscardPolicy : </strong>The thread will be discard. You will lose the thread.<br><strong>ThreadPoolExecutor.DiscardOldestPolicy : </strong>This policy discards the oldest unhandled request. You will lose some threads inside queue.</p><p><strong>4. Conclusion : </strong>This article will help to understand important concepts of Spring @Async feature. You can decide your ThreadPoolTaskExecutor configuration your with your application requirements. I’m suggesting to use monitoring tools for improve ThreadPoolTaskExecutor definitions. Please be careful about thread rejection policies otherwise you can use threads.</p><p>Thanks for reading this article!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f493903617d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/spring-boot-async-executor-management-with-threadpooltaskexecutor-f493903617d">Spring Boot Async Executor Management with ThreadPoolTaskExecutor</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>