package com.yuzhouwan.hacker.algorithms.thread.ttl;

import com.alibaba.ttl.TransmittableThreadLocal;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * Copyright @ 2018 yuzhouwan.com
 * All right reserved.
 * Function：Transmittable ThreadLocal Test
 *
 * @author Benedict Jin
 * @since 2018/6/7
 */
public class TransmittableThreadLocalTest {

    @Test
    public void parentChildThread() {
        ThreadLocal<String> tl = new ThreadLocal<>();
        tl.set("tl");
        TransmittableThreadLocal<String> ttl = new TransmittableThreadLocal<>();
        ttl.set("ttl");

        new Thread(() -> {
            assertEquals(tl.get(), null);
            assertEquals(ttl.get(), "ttl");
        }).start();
    }
}

@@ -420,16 +420,83 @@
         
+String tlMsg = %22tl%22;%0A        String ttlMsg = %22ttl%22;%0A%0A        final 
 ThreadLo
@@ -548,20 +548,21 @@
  tl.set(
-%22
 tl
-%22
+Msg
 );%0A     
@@ -564,16 +564,22 @@
         
+final 
 Transmit
@@ -659,21 +659,103 @@
 ttl.set(
-%22
 ttl
-%22
+Msg);%0A%0A        assertEquals(tl.get(), tlMsg);%0A        assertEquals(ttl.get(), ttlMsg
 );%0A%0A    
@@ -855,21 +855,22 @@
 .get(), 
-%22
 ttl
-%22
+Msg
 );%0A     

Improve TransmittableThreadLocal testcase