Skip to content

Commit

Permalink
#2878: provide interfaces compatible to 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
uweschaefer committed Jun 13, 2024
1 parent 0951eba commit 7d2acdb
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright © 2017-2022 factcast.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.factcast.factus.redis;

import lombok.NonNull;
import org.redisson.api.RedissonClient;

public abstract class AbstractRedisManagedProjection extends AbstractRedisProjection
implements RedisManagedProjection {
protected AbstractRedisManagedProjection(@NonNull RedissonClient redisson) {
super(redisson);

Check warning on line 24 in factcast-factus-redis/src/main/java/org/factcast/factus/redis/AbstractRedisManagedProjection.java

View check run for this annotation

Codecov / codecov/patch

factcast-factus-redis/src/main/java/org/factcast/factus/redis/AbstractRedisManagedProjection.java#L23-L24

Added lines #L23 - L24 were not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.factcast.factus.redis.tx;
package org.factcast.factus.redis;

import com.google.common.annotations.VisibleForTesting;
import java.time.Duration;
Expand All @@ -26,13 +26,10 @@
import org.factcast.factus.projection.Named;
import org.factcast.factus.projection.WriterToken;
import org.factcast.factus.projection.WriterTokenAware;
import org.factcast.factus.redis.FactStreamPositionCodec;
import org.factcast.factus.redis.RedisProjection;
import org.factcast.factus.redis.RedisWriterToken;
import org.redisson.api.*;

@SuppressWarnings("java:S2142")
abstract class AbstractRedisProjection
public abstract class AbstractRedisProjection
implements RedisProjection, FactStreamPositionAware, WriterTokenAware, Named {
@Getter protected final RedissonClient redisson;

Expand All @@ -52,7 +49,7 @@ protected AbstractRedisProjection(@NonNull RedissonClient redisson) {
}

@VisibleForTesting
RBucket<FactStreamPosition> stateBucket() {
protected RBucket<FactStreamPosition> stateBucket() {
return redisson.getBucket(stateBucketName, FactStreamPositionCodec.INSTANCE);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright © 2017-2022 factcast.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.factcast.factus.redis;

import lombok.NonNull;
import org.factcast.factus.projection.SubscribedProjection;
import org.redisson.api.RedissonClient;

public abstract class AbstractRedisSubscribedProjection extends AbstractRedisProjection
implements SubscribedProjection {
protected AbstractRedisSubscribedProjection(@NonNull RedissonClient redisson) {
super(redisson);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright © 2017-2022 factcast.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.factcast.factus.redis;

import org.factcast.factus.projection.ManagedProjection;

public interface RedisManagedProjection extends ManagedProjection, RedisProjection {}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.factcast.factus.projection.WriterTokenAware;
import org.factcast.factus.projection.tx.OpenTransactionAware;
import org.factcast.factus.projection.tx.TransactionBehavior;
import org.factcast.factus.redis.AbstractRedisProjection;
import org.factcast.factus.redis.FactStreamPositionCodec;
import org.factcast.factus.redis.RedisProjection;
import org.redisson.api.*;
Expand All @@ -44,12 +45,11 @@ protected AbstractRedisTxProjection(@NonNull RedissonClient redisson) {
super(redisson);
this.tx =
new TransactionBehavior<>(
new RedisTransactionAdapter(
redisson, getClass().getAnnotation(RedisTransactional.class)));
new RedisTxAdapter(redisson, getClass().getAnnotation(RedisTransactional.class)));
}

@VisibleForTesting
RBucket<FactStreamPosition> stateBucket(@NonNull RTransaction tx) {
protected RBucket<FactStreamPosition> stateBucket(@NonNull RTransaction tx) {
return tx.getBucket(stateBucketName, FactStreamPositionCodec.INSTANCE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.redisson.api.TransactionOptions;

@RequiredArgsConstructor
public class RedisTransactionAdapter implements TransactionAdapter<RTransaction> {
public class RedisTxAdapter implements TransactionAdapter<RTransaction> {
@NonNull private final RedissonClient client;
@Nullable private final RedisTransactional annotation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class AbstractRedisTxManagedProjectionTest {
class BucketFromThinAir {

@Test
void happyPath() {
void happyPathTx() {
RBucket<Object> bucket = mock(RBucket.class);
when(redisson.getBucket(any(), any())).thenReturn(bucket);
when(tx.getBucket(any(), any())).thenReturn(bucket);

assertThat(underTest.stateBucket()).isInstanceOf(RBucket.class).isSameAs(bucket);
verify(redisson)
assertThat(underTest.stateBucket(tx)).isInstanceOf(RBucket.class).isSameAs(bucket);
verify(tx)
.getBucket(underTest.redisKey() + "_state_tracking", FactStreamPositionCodec.INSTANCE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class RedisTransactionAdapterTest {
@Mock private RedisTransactional annotation;
@Mock private RTransaction tx;
@Mock private TransactionOptions opt;
@InjectMocks private RedisTransactionAdapter underTest;
@InjectMocks private RedisTxAdapter underTest;

@Nested
class WhenBeginingNewTransaction {
Expand Down Expand Up @@ -72,8 +72,7 @@ void usesDefaults() {
void overridesOptions() {

underTest =
new RedisTransactionAdapter(
client, Timeout12.class.getAnnotation(RedisTransactional.class));
new RedisTxAdapter(client, Timeout12.class.getAnnotation(RedisTransactional.class));

// TOptions does not support equals, so we're extracting the state to compare
Assertions.assertThat(FactCastJson.writeValueAsBytes(underTest.transactionOptions()))
Expand Down Expand Up @@ -126,8 +125,7 @@ void setup() {}

@Test
void readAnnotation() {
underTest =
new RedisTransactionAdapter(client, Bulk31.class.getAnnotation(RedisTransactional.class));
underTest = new RedisTxAdapter(client, Bulk31.class.getAnnotation(RedisTransactional.class));

// TOptions does not support equals, so we're extracting the state to compare
Assertions.assertThat(FactCastJson.writeValueAsBytes(underTest.transactionOptions()))
Expand All @@ -137,7 +135,7 @@ void readAnnotation() {

@Test
void usesDefault() {
underTest = new RedisTransactionAdapter(client, null);
underTest = new RedisTxAdapter(client, null);
Assertions.assertThat(underTest.maxBatchSizePerTransaction())
.isEqualTo(
new TransactionAdapter() {
Expand Down

0 comments on commit 7d2acdb

Please sign in to comment.