Skip to content

Instantly share code, notes, and snippets.

package com.mih.playground.driver;
import com.datastax.driver.core.utils.UUIDs;
import com.mih.playground.Infrastructure;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest;
import org.springframework.context.annotation.Import;
package com.mih.playground;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.utility.DockerImageName;
@mihaita-tinta
mihaita-tinta / DriverRepositoryTestcontainersTest.java
Last active December 22, 2023 14:40
junit testcontainer support
package com.mih.playground.driver;
import com.datastax.driver.core.utils.UUIDs;
import com.mih.playground.Infrastructure;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
package com.mih.playground.driver;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.stereotype.Repository;
import java.util.UUID;
@Repository
public interface DriverRepository extends CassandraRepository<Driver, UUID> {
}
@mihaita-tinta
mihaita-tinta / Driver.java
Created December 22, 2023 14:31
Simple entity stored in cassandra
package com.mih.playground.driver;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;
import java.time.ZonedDateTime;
import java.util.UUID;
@Table
public class Driver {
@mihaita-tinta
mihaita-tinta / MonitoringFileService.java
Created August 19, 2021 14:15
MonitoringFileService scans for changes for a given file
package com.mih.webauthn.demo.file;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.nio.file.*;
@mihaita-tinta
mihaita-tinta / LogsSseService.java
Created August 19, 2021 13:42
LogsSseService broadcast messages for each new line read from the file
package com.mih.webauthn.demo.file;
import com.mih.webauthn.demo.sse.SseTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.io.IOException;
import java.nio.file.Files;
@mihaita-tinta
mihaita-tinta / SseTemplate.java
Created August 19, 2021 13:32
SseTemplate allows creating sse connections and broadcast message on specific topics
package com.mih.webauthn.demo.sse;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
//...
CompletableFutureCacheableEvict evictAnnotation = invocation.getMethod().getAnnotation(CompletableFutureCacheableEvict.class);
//...
return callMethod(invocation)
.thenApply(newValue -> {
package com.mihaita.articles.caching;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;