<?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 Mehmet Emin Ak on Medium]]></title>
        <description><![CDATA[Stories by Mehmet Emin Ak on Medium]]></description>
        <link>https://medium.com/@mak44162?source=rss-8a92e73f1bbe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1PgidNTkw7jLRHSnZoPiiQ.jpeg</url>
            <title>Stories by Mehmet Emin Ak on Medium</title>
            <link>https://medium.com/@mak44162?source=rss-8a92e73f1bbe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:50:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mak44162/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[Exploring Testcontainers: A Game-Changer for Testing in Microservices Architecture]]></title>
            <link>https://medium.com/@mak44162/exploring-testcontainers-a-game-changer-for-testing-in-microservices-architecture-b6143a8bd364?source=rss-8a92e73f1bbe------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6143a8bd364</guid>
            <category><![CDATA[integration-testing]]></category>
            <category><![CDATA[testcontainer]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[java-spring-boot]]></category>
            <dc:creator><![CDATA[Mehmet Emin Ak]]></dc:creator>
            <pubDate>Wed, 04 Sep 2024 08:45:18 GMT</pubDate>
            <atom:updated>2024-09-04T08:45:18.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*pUUz3h3L0wKJ-VO7eGKMhg.png" /></figure><h3>Introduction</h3><p>In the world of software development, testing is a critical phase that ensures the quality and reliability of the applications we build. As applications become more complex, particularly with the adoption of microservices architecture, testing becomes increasingly challenging. Testcontainers, a Java library that supports JUnit tests, has emerged as a powerful tool to address these challenges. In this article, we’ll explore the use of Testcontainers in microservices architecture, discuss the problems it solves, weigh its advantages and disadvantages, and demonstrate how to write a test using Testcontainers with MongoDB.</p><h3>The Need for Testcontainers in Microservices Architecture</h3><h3>The Challenge of Testing Microservices</h3><p>Microservices architecture decomposes an application into a collection of loosely coupled services, each of which is developed, deployed, and scaled independently. While this approach offers flexibility and scalability, it introduces complexity, particularly when it comes to testing.</p><p>In a microservices environment, each service typically has its own database, message broker, or other dependencies. Testing these services in isolation can be challenging, as mocking external dependencies might not accurately reflect real-world scenarios. Traditional integration tests often require setting up a complex infrastructure that mimics the production environment, which can be cumbersome and time-consuming.</p><h3>Enter Testcontainers</h3><p>Testcontainers addresses these challenges by providing lightweight, throwaway instances of databases, message brokers, and other services running in Docker containers. These containers are spun up during the test execution and destroyed afterward, ensuring a clean and isolated environment for each test.</p><p>Testcontainers allows you to:</p><ul><li><strong>Spin up real instances of dependencies</strong>: Instead of relying on mocks, you can test your microservices against real instances of databases, message brokers, or even other services.</li><li><strong>Ensure consistent test environments</strong>: By using containers, you ensure that your tests run in the same environment every time, reducing the “works on my machine” problem.</li><li><strong>Simplify the test setup</strong>: Testcontainers manages the lifecycle of the containers, making it easy to set up and tear down dependencies.</li></ul><h3>Advantages of Using Testcontainers</h3><h3>1. Realistic Testing Environment</h3><p>One of the biggest advantages of Testcontainers is that it allows you to test against real instances of your dependencies. For example, instead of mocking a database, you can spin up a real MongoDB instance in a Docker container and run your tests against it. This ensures that your tests are as close to production as possible, reducing the risk of issues that only surface in production.</p><h3>2. Isolation of Tests</h3><p>Each test can run in a completely isolated environment, with its own instance of the dependencies. This prevents tests from interfering with each other and ensures that they are repeatable and reliable.</p><h3>3. Consistency Across Environments</h3><p>Since the dependencies are run in Docker containers, the environment in which your tests run is consistent across different machines and CI/CD pipelines. This eliminates issues caused by differences in the development and testing environments.</p><h3>4. Simplified Test Infrastructure</h3><p>Testcontainers manages the lifecycle of the containers for you, simplifying the setup and teardown of your test environment. You don’t need to worry about manually starting and stopping services or cleaning up resources after the tests are done.</p><h3>Disadvantages of Using Testcontainers</h3><h3>1. Dependency on Docker</h3><p>Testcontainers requires Docker to be installed and running on the machine where the tests are executed. This could be a limitation in environments where Docker is not available or allowed.</p><h3>2. Performance Overhead</h3><p>Spinning up Docker containers for each test can introduce a performance overhead, especially if your tests require many containers or if the containers are slow to start. However, this overhead is often outweighed by the benefits of having a realistic test environment.</p><h3>3. Complexity in CI/CD Pipelines</h3><p>Integrating Testcontainers into CI/CD pipelines can add complexity, particularly if your pipeline doesn’t already support Docker. However, many modern CI/CD tools, such as Jenkins, GitLab CI, and GitHub Actions, have good Docker support, which can mitigate this issue.</p><h3>4. Learning Curve</h3><p>While Testcontainers is relatively easy to use, it still requires some familiarity with Docker and containerization concepts. For teams that are new to Docker, there may be a learning curve.</p><h3>Use Case: Testing a Microservice with MongoDB</h3><p>Let’s consider a simple microservice that interacts with a MongoDB database. We want to write an integration test that ensures our service correctly saves and retrieves data from the database. Instead of setting up a MongoDB instance manually, we can use Testcontainers to spin up a MongoDB container just for the duration of the test.</p><h3>Example: Writing a Test with Testcontainers and MongoDB</h3><p>Firstly we are adding TestContainers dependency to our project.</p><p>If you are using Maven you can add this dependency to pom.xml file.</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;org.testcontainers&lt;/groupId&gt;<br>    &lt;artifactId&gt;testcontainers&lt;/artifactId&gt;<br>    &lt;version&gt;1.19.0&lt;/version&gt;<br>    &lt;scope&gt;test&lt;/scope&gt;<br>&lt;/dependency&gt;</pre><p>For Gradle</p><pre>testImplementation &quot;org.testcontainers:testcontainers:1.19.0&quot;</pre><p>Now, let’s set up the basic structure of our microservice. We’ll use Spring Boot for this example. Let’s create our User model.</p><pre>import org.springframework.data.annotation.Id;<br>import org.springframework.data.mongodb.core.mapping.Document;<br>import lombok.Data;<br><br>@Data<br>@Document(collection = &quot;users&quot;)<br>public class User {<br>    @Id<br>    private String id;<br>    private String name;<br>    private String email;<br>}</pre><p>Next, we’ll create a repository to interact with MongoDB.</p><pre>import org.springframework.data.mongodb.repository.MongoRepository;<br>import org.springframework.stereotype.Repository;<br><br>@Repository<br>public interface UserRepository extends MongoRepository&lt;User, String&gt; {<br>    User findByName(String name);<br>}</pre><p>Now, let’s write a test that uses Testcontainers to spin up a MongoDB instance.</p><pre>import org.junit.jupiter.api.Test;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;<br>import org.springframework.test.context.DynamicPropertyRegistry;<br>import org.springframework.test.context.DynamicPropertySource;<br>import org.testcontainers.containers.MongoDBContainer;<br>import org.testcontainers.junit.jupiter.Container;<br>import org.testcontainers.junit.jupiter.Testcontainers;<br><br>import static org.assertj.core.api.Assertions.assertThat;<br><br>@Testcontainers<br>@DataMongoTest<br>public class UserRepositoryTest {<br><br>    @Container<br>    static MongoDBContainer mongoDBContainer = new MongoDBContainer(&quot;mongo:latest&quot;);<br><br>    @Autowired<br>    private UserRepository userRepository;<br><br>    @DynamicPropertySource<br>    static void mongoDbProperties(DynamicPropertyRegistry registry) {<br>        //This code will update spring.data.mongodb.uri property while test running<br>        registry.add(&quot;spring.data.mongodb.uri&quot;, mongoDBContainer::getReplicaSetUrl);<br>    }<br><br>    @Test<br>    public void testSaveAndFindUser() {<br>        // Arrange<br>        User user = new User();<br>        user.setName(&quot;John Doe&quot;);<br>        user.setEmail(&quot;john.doe@example.com&quot;);<br><br>        // Act<br>        userRepository.save(user);<br>        User foundUser = userRepository.findByName(&quot;John Doe&quot;);<br><br>        // Assert<br>        assertThat(foundUser).isNotNull();<br>        assertThat(foundUser.getEmail()).isEqualTo(&quot;john.doe@example.com&quot;);<br>    }<br>}</pre><h3>Explanation</h3><ul><li><strong>@Testcontainers Annotation</strong>: This annotation is used to enable Testcontainers in the test class. It ensures that the Testcontainers lifecycle hooks are triggered.</li><li><strong>@Container Annotation</strong>: We define a static MongoDBContainer with the @Container annotation. This tells Testcontainers to manage the lifecycle of the MongoDB container.</li><li><strong>DynamicPropertySource Annotation</strong>: We use @DynamicPropertySource to dynamically set the MongoDB URI that Spring Boot will use to connect to the database. This URI is provided by the Testcontainers MongoDB instance.</li><li><strong>Test Logic</strong>: The test saves a User object to the database and then retrieves it by name. Finally, it asserts that the retrieved user is not null and that the email matches the expected value.</li></ul><h3>Running the Test</h3><p>When you run this test, Testcontainers will automatically download the MongoDB Docker image (if it’s not already available), spin up a MongoDB container, and run the test against this containerized database. Once the test is complete, the container will be stopped and removed.</p><h3>Conclusion</h3><p>Testcontainers is a powerful tool for testing microservices, particularly when it comes to testing interactions with external dependencies like databases and message brokers. By providing lightweight, disposable containers for these dependencies, Testcontainers allows you to create realistic and isolated test environments with minimal setup.</p><p>While there are some drawbacks, such as the dependency on Docker and potential performance overhead, the benefits often outweigh these concerns. In this article, we’ve demonstrated how Testcontainers can be used to test a microservice that interacts with MongoDB, but the same principles can be applied to other databases, message brokers, and services.</p><p>As microservices continue to grow in popularity, tools like Testcontainers will become increasingly important for ensuring that our applications are robust, reliable, and ready for production.</p><p>Don’t forget to follow me for more :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6143a8bd364" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PyScript nedir?]]></title>
            <link>https://medium.com/@mak44162/pyscript-nedir-d3ef4a51b961?source=rss-8a92e73f1bbe------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3ef4a51b961</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[türkçe]]></category>
            <category><![CDATA[pyscript]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Mehmet Emin Ak]]></dc:creator>
            <pubDate>Fri, 13 May 2022 15:50:01 GMT</pubDate>
            <atom:updated>2022-05-13T15:53:13.892Z</atom:updated>
            <content:encoded><![CDATA[<h3>Anaconda’dan Peter Wang, Fabio Pliger ve Philipp Rudiger’in içerisinde bulunduğu bir ekip tarafından geliştirilen PyScript, Peter’ın konuşmasında belirttiği gibi, Python’u PHP gibi HTML içerisinde yazabilmek için geliştirilen bir JavaScript framework’üdür. Bu, Python kodunu HTML dosyasının içerisinde yazıp çalıştırabileceğiniz anlamına gelir. Sizcede kulağa müthiş gelmiyor mu :)</h3><blockquote><strong>PyScript’i kullanmak dünya ve veri bilimcileri için ne anlama geliyor?</strong></blockquote><h3>En belirgin şey, PyScript ile artık Python’u (ve potansiyel olarak diğer dilleri) HTML’de yazabiliyor ve web uygulamaları oluşturabiliyoruz. PyScript, Python’un gücünü front-end kısmındaki geliştiriciler için erişilebilir kılar. Peter’ın konuşmada belirttiği gibi, “web tarayıcısı dünyanın en yaygın, taşınabilir bilgisayar ortamıdır.” Gerçekten de, ister bilgisayarda ister telefonda olsun, hemen hemen herkesin bir web tarayıcısına erişimi vardır. Bu, herhangi bir altyapı engeli olmaksızın herkesin erişebileceği ve programlamaya başlayabileceği anlamına gelir. Her şey web tarayıcınızda gerçekleşecek. Veri bilimcileri olarak, panolarımızı ve modellerimizi, başkaları dosyayı bir web tarayıcısında açtığında kodu çalıştıracak bir html dosyasında paylaşabiliriz.</h3><blockquote><strong>PyScript’in arkasındaki sihir nedir?</strong></blockquote><h3>PyScript şu anda “CPython’dan WebAssembly/Emscripten” ‘a port olan Pyodide üzerine kuruludur. PyScript, bir tarayıcıda Python kodu yazmayı ve çalıştırmayı destekler ve gelecekte diğer diller için destek sağlayacaktır.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*WCNNcGUnpiiJipdgOcCb0g.png" /></figure><blockquote><strong>WebAssembly nedir?</strong></blockquote><h3>Python’da web siteleri yazmayı mümkün kılan temel teknoloji WebAssembly’dir. WebAssembly ilk geliştirildiğinde, web tarayıcıları yalnızca Javascript’i destekliyordu. İlk olarak 2017&#39;de piyasaya sürülen WebAssembly, 2019&#39;a kadar hızla resmi World Wide Web Consortium (W3C) standardı haline geldi. WebAssembly insanlar tarafından okunabilen bir .wat formatında dosya içerir ve bu dosya daha sonra tarayıcıların çalıştırabileceği bir binary (ikili) .wasm formatına dönüştürülür. Bu, herhangi bir dilde kod yazmamızı, onu WebAssembly’de derlememizi ve ardından bir web tarayıcısında çalıştırmamızı sağlar.</h3><blockquote><strong>PyScript nasıl kullanılır?</strong></blockquote><h3>PyScript’in alfa sürümüne pyscript.net giderek ulaşabilirsiniz. Kodları <a href="https://github.com/pyscript">https://github.com/pyscript</a> adresinde mevcuttur. Denemek için bu talimatları izleyin. Öncelikle HTML sayfamıza pyscript.js dosyasını ve pyscript.css dosyasını include etmemiz lazım aşağıdaki kodları HTML dosyamıza yapıştırarak include ederiz.</h3><blockquote>&lt;link rel=”stylesheet” href=”https://pyscript.net/alpha/pyscript.css&quot; /&gt; &lt;script defer src=”https://pyscript.net/alpha/pyscript.js”&gt;&lt;/script&gt;</blockquote><h3>PyScript, aşağıdaki üç ana bileşeni kullanarak Python’u html’de yazmanıza izin verir:</h3><h3>1.py-env, Python kodunuzu çalıştırmak için gereken Python paketlerini tanımlar.</h3><h3>2.py-script, web sayfasında çalıştırılan Python kodunuzu yazdığınız yerdir.</h3><h3>3.py-repl, kullanıcıların girdiği kodu değerlendiren ve sonuçları görüntüleyen bir REPL (okuma-değerlendirme-yazdırma döngüsü) bileşeni oluşturur.</h3><blockquote><strong>py-env örneği</strong></blockquote><h3>Python ortamımızı py-env kullanarak bir HTML’de nasıl tanımlayabileceğimize dair bir örnek. Bu örnekte, bokeh, numpy, pandas ve scikit-learn paketlerini ortamımıza yüklüyoruz.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*lvVaEmQW-G6fAWKUwjcrJg.png" /></figure><blockquote><strong>py-script örneği</strong></blockquote><h3>Bu örnek, akış verileri içeren bir Panel panosunu gösterir. Kodda da görebileceğiniz gibi, normalde bir Python dosyasında yaptığımız gibi, Python kodumuzu py-script’e yazabiliyoruz. Python kodunuzu doğrudan py-script taglarının içine yazmayı sevmiyorsanız, kaynak kodu olarak bir Python dosyası da kullanabilirsiniz:</h3><blockquote>&lt;py-script&gt;Python Kodları&lt;/py-script&gt;</blockquote><h3>örneğin ;</h3><blockquote>&lt;py-script&gt; print(“Hello PyScript!”)&lt;/py-script&gt;</blockquote><h3>ya da bu şekilde kullanabilirsiniz:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aqweLXJ8uB2-UP5cIq55GQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LPYT6rJM-dhX-B7AGKLQTw.png" /></figure><blockquote><strong>py-repl örneği</strong> ;</blockquote><h3>Bu örnek, DeckGL ve REPL bileşenini kullanan NYC Taksi verileriyle bir Panel panosunu gösterir. Gördüğünüz gibi, REPL’de yarıçapı tanımlayabiliyor ve data framework’ünün (hour&lt; 3) subset’ini seçebiliyoruz.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*6GdB8wbAUPkBvreniT82Mg.gif" /></figure><h3>Yazımı buraya kadar okuduysanız teşekkür ediyor, bol kodlamalı günler diliyorum 😊</h3><h3>Yeni yazılarımda görüşmek üzere 👋</h3><p>Kaynakça</p><p><a href="https://www.anaconda.com/">https://www.anaconda.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3ef4a51b961" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>