You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2022/10/31 15:23:30 UTC

[camel-karavan] branch main updated: Fix #506

This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git


The following commit(s) were added to refs/heads/main by this push:
     new 027dbe9  Fix #506
027dbe9 is described below

commit 027dbe97082d21f17d12b2cd74dd4a91fa61416b
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Mon Oct 31 11:23:21 2022 -0400

    Fix #506
---
 karavan-core/src/core/api/CamelDefinitionYaml.ts |  2 +
 karavan-core/test/circuitBreaker.spec.ts         | 57 ++++++++++++++++++++++++
 karavan-core/test/circuitBreaker.yaml            | 12 +++++
 karavan-designer/src/App.tsx                     | 13 +++++-
 4 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/karavan-core/src/core/api/CamelDefinitionYaml.ts b/karavan-core/src/core/api/CamelDefinitionYaml.ts
index de4838a..769dc39 100644
--- a/karavan-core/src/core/api/CamelDefinitionYaml.ts
+++ b/karavan-core/src/core/api/CamelDefinitionYaml.ts
@@ -124,6 +124,8 @@ export class CamelDefinitionYaml {
                 || dslName?.endsWith('Expression')
                 || stepName === 'otherwise'
                 || stepName === 'doFinally'
+                || stepName === 'resilience4jConfiguration'
+                || stepName === 'faultToleranceConfiguration'
                 || key === 'from') {
                 delete newValue.inArray;
                 delete newValue.inSteps;
diff --git a/karavan-core/test/circuitBreaker.spec.ts b/karavan-core/test/circuitBreaker.spec.ts
new file mode 100644
index 0000000..5c32763
--- /dev/null
+++ b/karavan-core/test/circuitBreaker.spec.ts
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+import {expect} from 'chai';
+import 'mocha';
+import {
+    FromDefinition,
+    LogDefinition,
+    WhenDefinition,
+    ChoiceDefinition,
+    MulticastDefinition,
+    ExpressionDefinition,
+    RouteDefinition, TryDefinition,CatchDefinition
+} from "../src/core/model/CamelDefinition";
+import {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
+import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
+import {SimpleExpression} from "../src/core/model/CamelDefinition";
+import {Integration} from "../src/core/model/IntegrationDefinition";
+import * as fs from 'fs';
+import {CamelModelMetadata, ElementMeta} from "../lib/model/CamelMetadata";
+import {CircuitBreakerDefinition, Resilience4jConfigurationDefinition} from "../lib/model/CamelDefinition";
+
+describe('Circuit Breaker', () => {
+
+    it('Add Step', () => {
+        const i = Integration.createNew("circuitBreaker");
+        i.type = "plain"
+
+        const circuitBreaker = new CircuitBreakerDefinition({
+            resilience4jConfiguration: new Resilience4jConfigurationDefinition({minimumNumberOfCalls: 5, failureRateThreshold: 50}),
+            steps: [new LogDefinition({logName: 'log11', message: "hello11"})]
+        })
+        const flow1 = new FromDefinition({uri: "direct:direct1"});
+
+        flow1.steps?.push(circuitBreaker);
+        i.spec.flows?.push(new RouteDefinition({from:flow1}));
+
+        const yaml = CamelDefinitionYaml.integrationToYaml(i);
+        const yaml2 = fs.readFileSync('test/circuitBreaker.yaml',{encoding:'utf8', flag:'r'});
+        const i2 = CamelDefinitionYaml.yamlToIntegration("circuitBreaker.yaml", yaml2);
+        const yaml3 = CamelDefinitionYaml.integrationToYaml(i2);
+        expect(yaml).to.equal(yaml3);
+    });
+});
\ No newline at end of file
diff --git a/karavan-core/test/circuitBreaker.yaml b/karavan-core/test/circuitBreaker.yaml
new file mode 100644
index 0000000..4693adb
--- /dev/null
+++ b/karavan-core/test/circuitBreaker.yaml
@@ -0,0 +1,12 @@
+- route:
+    from:
+      uri: direct:direct1
+      steps:
+        - circuitBreaker:
+            steps:
+              - log:
+                  message: hello11
+                  logName: log11
+            resilience4jConfiguration:
+              minimumNumberOfCalls: 5
+              failureRateThreshold: 50
diff --git a/karavan-designer/src/App.tsx b/karavan-designer/src/App.tsx
index fbe93f1..aecf98d 100644
--- a/karavan-designer/src/App.tsx
+++ b/karavan-designer/src/App.tsx
@@ -42,7 +42,18 @@ class App extends React.Component<Props, State> {
     public state: State = {
         name: 'demo.yaml',
         key: '',
-        yaml: ''
+        yaml: '- route:\n' +
+            '    from:\n' +
+            '      uri: direct:direct1\n' +
+            '      steps:\n' +
+            '        - circuitBreaker:\n' +
+            '            steps:\n' +
+            '              - log:\n' +
+            '                  message: hello11\n' +
+            '                  logName: log11\n' +
+            '            resilience4jConfiguration:\n' +
+            '              minimumNumberOfCalls: 5\n' +
+            '              failureRateThreshold: 50\n'
         //     'apiVersion: camel.apache.org/v1\n' +
         //     'kind: Integration\n' +
         //     'metadata:\n' +