Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer api from project-reactor instead of creating our own wheel #24338

Merged
merged 1 commit into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.azure.spring.cloud.resourcemanager.implementation.crud.EventHubCrud;
import com.azure.spring.cloud.resourcemanager.implementation.crud.EventHubNamespaceCrud;
import com.azure.spring.core.properties.resource.AzureResourceMetadata;
import com.azure.spring.core.util.Triple;
import com.azure.spring.core.util.Tuple;
import com.azure.spring.eventhubs.core.EventHubProvisioner;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

/**
* Default implementation to provision an Event Hub.
Expand All @@ -35,12 +35,12 @@ public void provisionNamespace(String namespace) {

@Override
public void provisionEventHub(String namespace, String eventHub) {
this.eventHubCrud.getOrCreate(Tuple.of(namespace, eventHub));
this.eventHubCrud.getOrCreate(Tuples.of(namespace, eventHub));
}

@Override
public void provisionConsumerGroup(String namespace, String eventHub, String consumerGroup) {
this.consumerGroupCrud.getOrCreate(Triple.of(namespace, eventHub, consumerGroup));
this.consumerGroupCrud.getOrCreate(Tuples.of(namespace, eventHub, consumerGroup));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.spring.cloud.resourcemanager.implementation.crud.ServiceBusQueueCrud;
import com.azure.spring.core.properties.resource.AzureResourceMetadata;
import com.azure.spring.core.util.Tuple;
import com.azure.spring.servicebus.core.ServiceBusQueueProvisioner;
import reactor.util.function.Tuples;

/**
* A default implementation to provision Service Bus Queue.
Expand All @@ -23,7 +23,7 @@ public DefaultServiceBusQueueProvisioner(AzureResourceManager azureResourceManag

@Override
public void provisionQueue(String namespace, String queue) {
this.serviceBusQueueCrud.getOrCreate(Tuple.of(namespace, queue));
this.serviceBusQueueCrud.getOrCreate(Tuples.of(namespace, queue));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import com.azure.spring.cloud.resourcemanager.implementation.crud.ServiceBusTopicCrud;
import com.azure.spring.cloud.resourcemanager.implementation.crud.ServiceBusTopicSubscriptionCrud;
import com.azure.spring.core.properties.resource.AzureResourceMetadata;
import com.azure.spring.core.util.Triple;
import com.azure.spring.core.util.Tuple;
import com.azure.spring.servicebus.core.ServiceBusTopicProvisioner;
import reactor.util.function.Tuples;

/**
* A default implementation to provision Service Bus Topic.
Expand All @@ -27,11 +26,11 @@ public DefaultServiceBusTopicProvisioner(AzureResourceManager azureResourceManag

@Override
public void provisionTopic(String namespace, String topic) {
this.topicCrud.getOrCreate(Tuple.of(namespace, topic));
this.topicCrud.getOrCreate(Tuples.of(namespace, topic));
}

@Override
public void provisionSubscription(String namespace, String topic, String subscription) {
this.subscriptionCrud.getOrCreate(Triple.of(namespace, topic, subscription));
this.subscriptionCrud.getOrCreate(Tuples.of(namespace, topic, subscription));
}
}
6 changes: 6 additions & 0 deletions sdk/spring/azure-spring-cloud-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
<version>5.7.2</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.9</version> <!-- {x-version-update;org.springframework:spring-test;external_dependency} -->
<scope>test</scope>
</dependency>

<!-- Used to eliminate warnings when generate Java Docs.
Added this dependency to include necessary annotations used by reactor core.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
import java.util.function.Function;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

/**
* Memorize function execution result
Expand All @@ -25,11 +27,11 @@ public static <T, R> Function<T, R> memoize(Map<T, R> map, Function<T, R> fn) {
}

public static <T, U, R> BiFunction<T, U, R> memoize(BiFunction<T, U, R> biFunction) {
Map<Tuple<T, U>, R> map = new ConcurrentHashMap<>();
return (t, u) -> map.computeIfAbsent(Tuple.of(t, u), (k) -> biFunction.apply(k.getFirst(), k.getSecond()));
Map<Tuple2<T, U>, R> map = new ConcurrentHashMap<>();
return (t, u) -> map.computeIfAbsent(Tuples.of(t, u), (k) -> biFunction.apply(k.getT1(), k.getT2()));
}

public static <T, U, R> BiFunction<T, U, R> memoize(Map<Tuple<T, U>, R> map, BiFunction<T, U, R> biFunction) {
return (t, u) -> map.computeIfAbsent(Tuple.of(t, u), (k) -> biFunction.apply(k.getFirst(), k.getSecond()));
public static <T, U, R> BiFunction<T, U, R> memoize(Map<Tuple2<T, U>, R> map, BiFunction<T, U, R> biFunction) {
return (t, u) -> map.computeIfAbsent(Tuples.of(t, u), (k) -> biFunction.apply(k.getT1(), k.getT2()));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package com.azure.spring.cloud.context.core;

import com.azure.spring.core.util.Memoizer;
import com.azure.spring.core.util.Tuple;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
import java.util.function.Function;
import reactor.util.function.Tuple2;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void memoizeFuncWithMap() {

@Test
public void memoizeBiFuncWithMap() {
Map<Tuple<String, String>, String> map = new ConcurrentHashMap<>();
Map<Tuple2<String, String>, String> map = new ConcurrentHashMap<>();
ExpensiveBiOperation expensiveOperation = mock(ExpensiveBiOperation.class);
when(expensiveOperation.compute(INPUT, INPUT2)).thenReturn(OUTPUT);
BiFunction<String, String, String> memoized = Memoizer.memoize(map, expensiveOperation::compute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.eventhubs.models.EventHubConsumerGroup;
import com.azure.spring.core.properties.resource.AzureResourceMetadata;
import com.azure.spring.core.util.Triple;
import com.azure.spring.core.util.Tuple;
import reactor.util.function.Tuple3;
import reactor.util.function.Tuples;


/**
* Resource manager for Event Hubs consumer group.
*/
public class EventHubConsumerGroupCrud
extends AbstractResourceCrud<EventHubConsumerGroup, Triple<String, String, String>> {
extends AbstractResourceCrud<EventHubConsumerGroup, Tuple3<String, String, String>> {

public EventHubConsumerGroupCrud(AzureResourceManager azureResourceManager,
AzureResourceMetadata resourceMetadata) {
super(azureResourceManager, resourceMetadata);
}

@Override
String getResourceName(Triple<String, String, String> key) {
return key.getThird();
String getResourceName(Tuple3<String, String, String> key) {
return key.getT3();
}

@Override
Expand All @@ -32,13 +33,13 @@ String getResourceType() {
}

@Override
public EventHubConsumerGroup internalGet(Triple<String, String, String> consumerGroupCoordinate) {
public EventHubConsumerGroup internalGet(Tuple3<String, String, String> consumerGroupCoordinate) {
try {
return this.resourceManager
.eventHubs()
.consumerGroups()
.getByName(this.resourceMetadata.getResourceGroup(), consumerGroupCoordinate.getFirst(),
consumerGroupCoordinate.getSecond(), consumerGroupCoordinate.getThird());
.getByName(this.resourceMetadata.getResourceGroup(), consumerGroupCoordinate.getT1(),
consumerGroupCoordinate.getT2(), consumerGroupCoordinate.getT3());
} catch (ManagementException e) {
if (e.getResponse().getStatusCode() == 404) {
return null;
Expand All @@ -49,14 +50,14 @@ public EventHubConsumerGroup internalGet(Triple<String, String, String> consumer
}

@Override
public EventHubConsumerGroup internalCreate(Triple<String, String, String> consumerGroupCoordinate) {
public EventHubConsumerGroup internalCreate(Tuple3<String, String, String> consumerGroupCoordinate) {
return this.resourceManager
.eventHubs()
.consumerGroups()
.define(consumerGroupCoordinate.getSecond())
.define(consumerGroupCoordinate.getT2())
.withExistingEventHub(new EventHubCrud(this.resourceManager, this.resourceMetadata)
.getOrCreate(Tuple.of(consumerGroupCoordinate.getFirst(),
consumerGroupCoordinate.getSecond())))
.getOrCreate(Tuples.of(consumerGroupCoordinate.getT1(),
consumerGroupCoordinate.getT2())))
.create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.eventhubs.models.EventHub;
import com.azure.spring.core.properties.resource.AzureResourceMetadata;
import com.azure.spring.core.util.Tuple;
import reactor.util.function.Tuple2;

/**
* Resource manager for Event Hubs.
*/
public class EventHubCrud extends AbstractResourceCrud<EventHub, Tuple<String, String>> {
public class EventHubCrud extends AbstractResourceCrud<EventHub, Tuple2<String, String>> {

public EventHubCrud(AzureResourceManager azureResourceManager, AzureResourceMetadata azureResourceMetadata) {
super(azureResourceManager, azureResourceMetadata);
}

@Override
String getResourceName(Tuple<String, String> key) {
return key.getSecond();
String getResourceName(Tuple2<String, String> key) {
return key.getT2();
}

@Override
Expand All @@ -29,12 +29,12 @@ String getResourceType() {
}

@Override
public EventHub internalGet(Tuple<String, String> namespaceAndName) {
public EventHub internalGet(Tuple2<String, String> namespaceAndName) {
try {
return this.resourceManager.eventHubs()
.getByName(this.resourceMetadata.getResourceGroup(),
namespaceAndName.getFirst(),
namespaceAndName.getSecond());
namespaceAndName.getT1(),
namespaceAndName.getT2());
} catch (ManagementException e) {
if (e.getResponse().getStatusCode() == 404) {
return null;
Expand All @@ -45,12 +45,12 @@ public EventHub internalGet(Tuple<String, String> namespaceAndName) {
}

@Override
public EventHub internalCreate(Tuple<String, String> namespaceAndName) {
public EventHub internalCreate(Tuple2<String, String> namespaceAndName) {
return this.resourceManager.eventHubs()
.define(namespaceAndName.getSecond())
.define(namespaceAndName.getT2())
.withExistingNamespace(new EventHubNamespaceCrud(this.resourceManager,
this.resourceMetadata)
.getOrCreate(namespaceAndName.getFirst()))
.getOrCreate(namespaceAndName.getT1()))
.create();
}
}
Loading