|
| 1 | +/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
| 2 | +
|
| 3 | +This program is free software; you can redistribute it and/or modify |
| 4 | +it under the terms of the GNU General Public License as published by |
| 5 | +the Free Software Foundation; version 2 of the License. |
| 6 | +
|
| 7 | +This program is distributed in the hope that it will be useful, |
| 8 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | +GNU General Public License for more details. |
| 11 | +
|
| 12 | +You should have received a copy of the GNU General Public License |
| 13 | +along with this program; if not, write to the Free Software |
| 14 | +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 15 | + |
| 16 | +#include <mysql/components/component_implementation.h> |
| 17 | +#include <mysql/components/service_implementation.h> |
| 18 | +#include <mysql/components/services/system_variable_source.h> |
| 19 | +#include "../../components/mysql_server/system_variable_source_imp.h" |
| 20 | + |
| 21 | +#include <fcntl.h> |
| 22 | +#include <stdio.h> |
| 23 | +#include <typelib.h> |
| 24 | + |
| 25 | +#define MAX_BUFFER_LENGTH 100 |
| 26 | +int log_text_len= 0; |
| 27 | +char log_text[MAX_BUFFER_LENGTH]; |
| 28 | +FILE *outfile; |
| 29 | +const char *filename= "test_system_variable_source.log"; |
| 30 | + |
| 31 | +#define WRITE_LOG(lit_log_text) \ |
| 32 | + log_text_len= sprintf(log_text, "%s", lit_log_text); \ |
| 33 | + fwrite((uchar*)log_text, sizeof(char), log_text_len, outfile) |
| 34 | + |
| 35 | +REQUIRES_SERVICE_PLACEHOLDER(system_variable_source); |
| 36 | + |
| 37 | +/** |
| 38 | + This file contains a test (example) component, which tests the services of |
| 39 | + "system_variable_source" service provided by "mysql_server" component. |
| 40 | +*/ |
| 41 | + |
| 42 | +/** |
| 43 | + Initialization entry method for test component. It executes the tests of |
| 44 | + the service. |
| 45 | +*/ |
| 46 | +static mysql_service_status_t test_system_variable_source_init() |
| 47 | +{ |
| 48 | + outfile= fopen(filename, "w+"); |
| 49 | + |
| 50 | + WRITE_LOG("test_system_variable_source_init start:\n"); |
| 51 | + |
| 52 | + enum enum_variable_source source; |
| 53 | + if (mysql_service_system_variable_source->get( |
| 54 | + "innodb_buffer_pool_size", 23, |
| 55 | + &source)) |
| 56 | + { |
| 57 | + WRITE_LOG ("get failed for innodb_buffer_pool_size.\n"); |
| 58 | + } |
| 59 | + else |
| 60 | + { |
| 61 | + WRITE_LOG ("Source of innodb_buffer_pool_size : "); |
| 62 | + switch(source) |
| 63 | + { |
| 64 | + case COMPILED: |
| 65 | + WRITE_LOG(" COMPILED.\n"); |
| 66 | + break; |
| 67 | + case GLOBAL: |
| 68 | + WRITE_LOG(" GLOBAL.\n"); |
| 69 | + break; |
| 70 | + case SERVER: |
| 71 | + WRITE_LOG(" SERVER.\n"); |
| 72 | + break; |
| 73 | + case EXPLICIT: |
| 74 | + WRITE_LOG(" EXPLICIT.\n"); |
| 75 | + break; |
| 76 | + case EXTRA: |
| 77 | + WRITE_LOG(" EXTRA.\n"); |
| 78 | + break; |
| 79 | + case MYSQL_USER: |
| 80 | + WRITE_LOG(" MYSQL_USER.\n"); |
| 81 | + break; |
| 82 | + case LOGIN: |
| 83 | + WRITE_LOG(" LOGIN.\n"); |
| 84 | + break; |
| 85 | + case COMMAND_LINE: |
| 86 | + WRITE_LOG(" COMMAND_LINE.\n"); |
| 87 | + break; |
| 88 | + case PERSISTED: |
| 89 | + WRITE_LOG(" PERSISTED.\n"); |
| 90 | + break; |
| 91 | + case DYNAMIC: |
| 92 | + WRITE_LOG(" DYNAMIC.\n"); |
| 93 | + break; |
| 94 | + default: /* We should never reach here */ |
| 95 | + WRITE_LOG(" INVALID.\n"); |
| 96 | + break; |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + WRITE_LOG("test_system_variable_source_init end:\n\n"); |
| 101 | + fclose(outfile); |
| 102 | + |
| 103 | + return false; |
| 104 | +} |
| 105 | + |
| 106 | +/** |
| 107 | + De-initialization method for Component. |
| 108 | +*/ |
| 109 | +static mysql_service_status_t test_system_variable_source_deinit() |
| 110 | +{ |
| 111 | + /* Nothing to do */ |
| 112 | + return false; |
| 113 | +} |
| 114 | + |
| 115 | +/* An empty list as no service is provided. */ |
| 116 | +BEGIN_COMPONENT_PROVIDES(test_system_variable_source) |
| 117 | +END_COMPONENT_PROVIDES() |
| 118 | + |
| 119 | +/* A list of required services. */ |
| 120 | +BEGIN_COMPONENT_REQUIRES(test_system_variable_source) |
| 121 | + REQUIRES_SERVICE(system_variable_source) |
| 122 | +END_COMPONENT_REQUIRES() |
| 123 | + |
| 124 | +/* A list of metadata to describe the Component. */ |
| 125 | +BEGIN_COMPONENT_METADATA(test_system_variable_source) |
| 126 | + METADATA("mysql.author", "Oracle Corporation") |
| 127 | + METADATA("mysql.license", "GPL") |
| 128 | + METADATA("test_system_variable_source", "1") |
| 129 | +END_COMPONENT_METADATA() |
| 130 | + |
| 131 | +/* Declaration of the Component. */ |
| 132 | +DECLARE_COMPONENT(test_system_variable_source, "mysql:test_system_variable_source") |
| 133 | + test_system_variable_source_init, |
| 134 | + test_system_variable_source_deinit |
| 135 | +END_DECLARE_COMPONENT() |
| 136 | + |
| 137 | +/* Defines list of Components contained in this library. Note that for now we |
| 138 | + assume that library will have exactly one Component. */ |
| 139 | +DECLARE_LIBRARY_COMPONENTS |
| 140 | + &COMPONENT_REF(test_system_variable_source) |
| 141 | +END_DECLARE_LIBRARY_COMPONENTS |
0 commit comments